Skip to content

Commit

Permalink
Introduce report_command_status helper function
Browse files Browse the repository at this point in the history
Instead of repeating near identical code several times
in manage.c, use a small helper function instead.

Change-Id: I91f739f5cb43386b2ce767cf3603a76e6b93e216
Acked-by: Frank Lichtenheld <[email protected]>
Signed-off-by: Arne Schwabe <[email protected]>
Message-Id: <[email protected]>
URL: https://www.mail-archive.com/[email protected]/msg27525.html
Signed-off-by: Gert Doering <[email protected]>
  • Loading branch information
schwabe authored and cron2 committed Nov 21, 2023
1 parent 78e0c5f commit 57172d8
Showing 1 changed file with 21 additions and 24 deletions.
45 changes: 21 additions & 24 deletions src/openvpn/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,24 @@ man_prompt(struct management *man)
#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)
{
Expand Down Expand Up @@ -974,14 +992,7 @@ in_extra_dispatch(struct management *man)
NULL,
man->connection.in_extra);
man->connection.in_extra = 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
{
Expand Down Expand Up @@ -1260,14 +1271,7 @@ man_proxy(struct management *man, const char **p)
if (man->persist.callback.proxy_cmd)
{
const bool status = (*man->persist.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
{
Expand All @@ -1281,14 +1285,7 @@ man_remote(struct management *man, const char **p)
if (man->persist.callback.remote_cmd)
{
const bool status = (*man->persist.callback.remote_cmd)(man->persist.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
{
Expand Down

0 comments on commit 57172d8

Please sign in to comment.