Skip to content

Commit

Permalink
Add: Added the appliance_status response field to the get_license com…
Browse files Browse the repository at this point in the history
…mand

Merge pull request #1786 from jhelmold/appliance_status_response_field
  • Loading branch information
timopollmeier authored Feb 24, 2022
2 parents 2d66c14 + 7708246 commit c9affb5
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 7 deletions.
11 changes: 8 additions & 3 deletions src/gmp_license.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,15 @@ get_license_run (gmp_parser_t *gmp_parser,
int ret;

gchar *license_status;
gchar *appliance_status;
theia_license_t *license_data;

license_status = NULL;
license_data = NULL;

ret = manage_get_license (&license_status,
&license_data);
&license_data,
&appliance_status);

switch (ret)
{
Expand All @@ -200,10 +202,12 @@ get_license_run (gmp_parser_t *gmp_parser,
"<get_license_response status=\"%s\""
" status_text=\"%s\">"
"<license>"
"<status>%s</status>",
"<status>%s</status>"
"<appliance_status>%s</appliance_status>",
STATUS_OK,
STATUS_OK_TEXT,
license_status);
license_status,
appliance_status ? appliance_status : "");

if (license_data)
{
Expand Down Expand Up @@ -245,6 +249,7 @@ get_license_run (gmp_parser_t *gmp_parser,
}

g_free (license_status);
g_free (appliance_status);

#ifdef HAS_LIBTHEIA
theia_license_free (license_data);
Expand Down
46 changes: 43 additions & 3 deletions src/manage_license.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "manage_acl.h"
#include "manage_license.h"
#include "utils.h"
#include "manage_sql.h"

#undef G_LOG_DOMAIN
/**
Expand Down Expand Up @@ -166,21 +167,55 @@ manage_update_license_file (const char *new_license,
return 0;
}

#ifdef HAS_LIBTHEIA

/**
* @brief Get the current appliance status
*
* @param[in] got_license_info The info about the received license
*
* @return appliance status or NULL if not available
*/
static gchar*
get_appliance_status(theia_got_license_info_t *gli)
{
gchar *comm_app;
gchar *app_status;

comm_app = get_community_appliance_value ();

if (comm_app && atoi (comm_app))
app_status = g_strdup("community");
else if (gli && gli->license && gli->license->meta)
app_status = g_strdup_printf ("%s_%s", gli->license->meta->type,
gli->status);
else
app_status = NULL;

return app_status;
}

#endif // HAS_LIBTHEIA

/**
* @brief Get the current license information.
*
* @param[out] status The validation status (e.g. "valid", "expired").
* @param[out] license_data The content of the license organized in a struct.
* @param[out] status The validation status (e.g. "valid", "expired").
* @param[out] license_data The content of the license organized in a struct.
* @param[out] appliance_status The status of the appliance.
*
* @return 0 success, 1 service unavailable, 2 error sending command,
* 3 error receiving response, 99 permission denied, -1 internal error.
*/
int
manage_get_license (gchar **status,
theia_license_t **license_data)
theia_license_t **license_data,
gchar **appliance_status)
{
if (status)
*status = NULL;
if (appliance_status)
*appliance_status = NULL;
if (license_data)
*license_data = NULL;

Expand Down Expand Up @@ -260,6 +295,11 @@ manage_get_license (gchar **status,

theia_client_disconnect (client);

if (appliance_status)
{
*appliance_status = get_appliance_status(got_license_info);
}

if (status)
{
*status = got_license_info->status;
Expand Down
2 changes: 1 addition & 1 deletion src/manage_license.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ int
manage_update_license_file (const char *, gboolean *, char **);

int
manage_get_license (char **, theia_license_t **);
manage_get_license (gchar **, theia_license_t **, gchar**);
12 changes: 12 additions & 0 deletions src/manage_sql.c
Original file line number Diff line number Diff line change
Expand Up @@ -55493,6 +55493,18 @@ delete_permissions_cache_for_user (user_t user)
sql ("DELETE FROM permissions_get_tasks WHERE \"user\" = %llu;", user);
}

/**
* @brief Get the community appliance value
*
* @return community appliance value or NULL if not available or on error
*/
gchar *
get_community_appliance_value ()
{
return (sql_string ("SELECT value from public.meta"
" where name = 'community_appliance';"));
}


/* Optimize. */

Expand Down
4 changes: 4 additions & 0 deletions src/manage_sql.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,8 @@ config_family_entire_and_growing (config_t, const char*);
void
reports_clear_count_cache_dynamic ();


gchar *
get_community_appliance_value ();

#endif /* not _GVMD_MANAGE_SQL_H */
7 changes: 7 additions & 0 deletions src/schema_formats/XML/GMP.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -12632,13 +12632,19 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<summary>The license information</summary>
<pattern>
<e>status</e>
<e>appliance_status</e>
<e>content</e>
</pattern>
<ele>
<name>status</name>
<summary>Status of the license</summary>
<pattern>text</pattern>
</ele>
<ele>
<name>appliance_status</name>
<summary>Status of the appliance</summary>
<pattern>text</pattern>
</ele>
<ele>
<name>content</name>
<summary>The main content of the license file</summary>
Expand Down Expand Up @@ -12776,6 +12782,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
<get_license_response status="200" status_text="OK">
<license>
<status>active</status>
<appliance_status>commercial_active</appliance_status>
<content>
<meta>
<id>4711</id>
Expand Down

0 comments on commit c9affb5

Please sign in to comment.