From: "cron2 (Code Review)" Date: Tue, 21 Nov 2023 19:18:29 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="m95Of64hh/8="; 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: plaisthos Cc: flichtenheld , openvpn-devel --m95Of64hh/8= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/45= 0?usp=3Demail ) 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 Acked-by: Frank Lichtenheld Signed-off-by: Arne Schwabe Message-Id: <20231121104254.15701-1-frank@...2641...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg27= 525.html Signed-off-by: Gert Doering --- M src/openvpn/manage.c 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c index feb62b2..27b6f90 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: 2 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-MessageType: merged --m95Of64hh/8= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 submitted this change.

View Change

Introduce report_command_status helper functio=
n

Instead of repeating near identical code several times
in manag= e.c, use a small helper function instead.

Change-Id: I91f739f5cb4338= 6b2ce767cf3603a76e6b93e216
Acked-by: Frank Lichtenheld <frank@...2746...= ...>
Signed-off-by: Arne Schwabe <arne@...1227...>
Message-I= d: <20231121104254.15701-1-frank@...2641...>
URL: https://www.mail= -archive.com/openvpn-devel@lists.sourceforge.net/msg27525.html
Signed-of= f-by: Gert Doering <gert@...1296...>
---
M src/openvpn/manage.c=
1 file changed, 21 insertions(+), 24 deletions(-)

diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index feb62b2..27b6f90 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 t= o
+ * the management = interface
+ */=
+static void
+report_command_status(const bool s= tatus, const char *command)

+{
+ if (st= atus)
+ {+ 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_ex= tra);
man->connection.in_extra =3D NULL= ;
- if (= status)
- = {
- = msg(M_CLIENT, "SUCCESS: client-auth command succeeded");=
- }
= - else
<= span style=3D"color: hsl(0, 100%, 40%);">- {
- msg(M_CLIENT, &qu= ot;ERROR: client-auth command failed");
- }
+ report_command_status(status, "cl= ient-auth");
}
= else
{
@@ -1260,14 +1271,7 = @@
if (man->persist.callback.proxy_cmd)
<= span> {
const bool status =3D (*man->persis= t.callback.proxy_cmd)(man->persist.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
{
@@ -1= 281,14 +1285,7 @@
if (man->persist.callback.remote_= cmd)
{
const bool status =3D = (*man->persist.callback.remote_cmd)(man->persist.callback.arg, p);
- if (status)
- {
- msg(M_CLIENT, "SUCCES= S: remote command succeeded");
- }
- else
- = {
- msg(M_C= LIENT, "ERROR: remote command failed");
- }
+ report_command_status(status, "remote")= ;
}
else
{

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

<= /div>
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I91f739f5cb43386b2ce767cf360= 3a76e6b93e216
Gerrit-Change-Number: 450
Gerrit-PatchSet: 2
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-MessageType: merged
--m95Of64hh/8=--