From: "plaisthos (Code Review)" Date: Mon, 20 Nov 2023 11:36:23 +0000 References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <27edbc35477fa10a89a73be7eadba0fc3b71d705-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="Gm3RW8+jzM0="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: Introduce report_command_status helper function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --Gm3RW8+jzM0= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld. Hello flichtenheld, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/450?usp=3Demail to review the following change. Change subject: Introduce report_command_status helper function ...................................................................... Introduce report_command_status helper function Instead of repeating near identical code several times in manage.c, use a small helper function instead. Change-Id: I91f739f5cb43386b2ce767cf3603a76e6b93e216 --- M src/openvpn/manage.c 1 file changed, 21 insertions(+), 24 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/50/450/1 diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index feb62b2..3cf392a 100644 --- a/src/openvpn/manage.c +++ b/src/openvpn/manage.c @@ -284,6 +284,24 @@ #endif } + +/** + * Small function to report the success or failure of a command to + * the management interface + */ +static void +report_command_status(const bool status, const char *command) +{ + if (status) + { + msg(M_CLIENT, "SUCCESS: %s command succeeded", command); + } + else + { + msg(M_CLIENT, "ERROR: %s command failed", command); + } +} + static void man_delete_unix_socket(struct management *man) { @@ -974,14 +992,7 @@ NULL, man->connection.in_extra); man->connection.in_extra =3D NULL; - if (status) - { - msg(M_CLIENT, "SUCCESS: client-auth command succeeded"= ); - } - else - { - msg(M_CLIENT, "ERROR: client-auth command failed"); - } + report_command_status(status, "client_auth"); } else { @@ -1260,14 +1271,7 @@ if (man->persist.callback.proxy_cmd) { const bool status =3D (*man->persist.callback.proxy_cmd)(man->pers= ist.callback.arg, p); - if (status) - { - msg(M_CLIENT, "SUCCESS: proxy command succeeded"); - } - else - { - msg(M_CLIENT, "ERROR: proxy command failed"); - } + report_command_status(status, "proxy"); } else { @@ -1281,14 +1285,7 @@ if (man->persist.callback.remote_cmd) { const bool status =3D (*man->persist.callback.remote_cmd)(man->per= sist.callback.arg, p); - if (status) - { - msg(M_CLIENT, "SUCCESS: remote command succeeded"); - } - else - { - msg(M_CLIENT, "ERROR: remote command failed"); - } + report_command_status(status, "remote"); } else { -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/450?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I91f739f5cb43386b2ce767cf3603a76e6b93e216 Gerrit-Change-Number: 450 Gerrit-PatchSet: 1 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld Gerrit-MessageType: newchange --Gm3RW8+jzM0= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld.

plaisthos would like flichtenheld to review this change.

Vi= ew Change

Introduce report_command_status helper function

Instea= d of repeating near identical code several times
in manage.c, use a smal= l helper function instead.

Change-Id: I91f739f5cb43386b2ce767cf3603a= 76e6b93e216
---
M src/openvpn/manage.c
1 file changed, 21 insertio= ns(+), 24 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/op=
envpn refs/changes/50/450/1
diff --git a/src/openvpn/manage.c b/src=
/openvpn/manage.c
index feb62b2..3cf392a 100644
<= span>--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c<= /span>
@@ -284,6 +284,24 @@
#endif
}


+/**
+ * Small function to report the = success or failure of a command to
+ * the management interface
+ */
+static void
+r= eport_command_status(const bool status, const char *command)
+{
+ if (status)
+ {
+ msg(M_CLIENT, "SUCCESS: %s command succeeded", comma= nd);
+ }+ else
+ {
+ msg(M_CLIENT, "ERROR: %s command failed&q= uot;, command);
+ = }
+}
+
static void=
man_delete_unix_socket(struct management *man)
= {
@@ -974,14 +992,7 @@
= NULL,
= man->connection.in_extra);
man= ->connection.in_extra =3D NULL;
- if (status)
- {
- msg(M_CLIENT, "SUCCESS: client-auth= command succeeded");
- }
= - else
-= {
- = msg(M_CLIENT, "ERROR: client-auth command failed"= );
- }
+ repor= t_command_status(status, "client_auth");
= }
else
{
@@ -1260,14 +1271,7 @@
if (man->persis= t.callback.proxy_cmd)
{
const= bool status =3D (*man->persist.callback.proxy_cmd)(man->persist.call= back.arg, p);
- = if (status)
- {<= /span>
- msg(M_CLIE= NT, "SUCCESS: proxy command succeeded");
- }
- else
- {
- = msg(M_CLIENT, "ERROR: proxy command failed");
<= span style=3D"color: hsl(0, 100%, 40%);">- }

+ report_command_status(status, &qu= ot;proxy");
}
else {
@@ -1281,14 +1285,7 @@
i= f (man->persist.callback.remote_cmd)
{
const bool status =3D (*man->persist.callback.remote_cmd)(m= an->persist.callback.arg, p);

- if (status)
- {
- = msg(M_CLIENT, "SUCCESS: remote command succeeded");

- }
- else
- {
- msg(M_CLIENT, "ERROR: remote command faile= d");
- }

+ report_command= _status(status, "remote");
}
else
{

To vi= ew, visit change 450. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I91f739f5cb43386b2ce767cf360= 3a76e6b93e216
Gerrit-Change-Number: 450
Gerrit-PatchSet: 1
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newchange
--Gm3RW8+jzM0=--