Skip to content

Commit

Permalink
Merge pull request #1744 from jhelmold/upload_status_modify_license
Browse files Browse the repository at this point in the history
The upload status of the modify license command is passed to GSA.
  • Loading branch information
timopollmeier authored Nov 25, 2021
2 parents 485b0fa + 78e6ea0 commit 29c1b98
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 9 deletions.
27 changes: 20 additions & 7 deletions src/gmp_license.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,19 @@ modify_license_element_start (gmp_parser_t *gmp_parser,
*
* @param[in] file_content The content of the new license file.
* @param[in] allow_empty Whether to allow an empty file.
* @param[out] error_msg The error message of the license update if any
*
* @return 0 success, 1 service unavailable, 2 empty file not allowed,
* 99 permission denied.
*/
static int
modify_license (gchar *file_content, gboolean allow_empty)
modify_license (gchar *file_content, gboolean allow_empty, char **error_msg)
{
if (allow_empty == FALSE
&& (file_content == NULL || strcmp (file_content, "") == 0))
return 4;

return manage_update_license_file(file_content);
return manage_update_license_file(file_content, error_msg);
}

/**
Expand All @@ -388,7 +389,8 @@ modify_license_run (gmp_parser_t *gmp_parser,
GError **error)
{
entity_t entity, file_entity;
const char* allow_empty_str;
const char *allow_empty_str;
char *error_msg;
int allow_empty, ret;

entity = (entity_t) modify_license_data.context->first->data;
Expand All @@ -398,7 +400,8 @@ modify_license_run (gmp_parser_t *gmp_parser,

file_entity = entity_child (entity, "file");

ret = modify_license (file_entity ? file_entity->text : NULL, allow_empty);
ret = modify_license (file_entity ? file_entity->text : NULL, allow_empty,
&error_msg);
switch (ret)
{
case 0:
Expand Down Expand Up @@ -428,9 +431,19 @@ modify_license_run (gmp_parser_t *gmp_parser,
"A non-empty FILE is required."));
break;
case 5:
SENDF_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("modify_license",
"License could not be updated."));
if (error_msg)
{
SENDF_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("modify_license",
"%s"), error_msg);
g_free (error_msg);
}
else
{
SENDF_TO_CLIENT_OR_FAIL
(XML_ERROR_SYNTAX ("modify_license",
"License could not be updated."));
}
break;
case 99:
SEND_TO_CLIENT_OR_FAIL (XML_ERROR_ACCESS ("modify_license"));
Expand Down
6 changes: 5 additions & 1 deletion src/manage_license.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@
* @brief Update the license file by replacing it with the given one.
*
* @param[in] new_license The content of the new license.
* @param[out] error_msg The error message of the license update if any
*
* @return 0 success, 1 service unavailable, 2 error sending command,
* 3 error receiving response, 4 no new_license data,
* 5 error updating license, 99 permission denied, -1 internal error.
*/
int
manage_update_license_file (const char *new_license)
manage_update_license_file (const char *new_license, char **error_msg)
{
*error_msg = NULL;

if (new_license == NULL)
return 4;
if (! acl_user_may ("modify_license"))
Expand Down Expand Up @@ -130,6 +133,7 @@ manage_update_license_file (const char *new_license)
{
g_message ("%s: Upload of new license file failed. Error: %s.\n",
__func__, failure_modify_license_info->error);
*error_msg = g_strdup (failure_modify_license_info->error);
theia_client_disconnect (client);
theia_modified_license_info_free (modified_license_info);
theia_failure_modify_license_info_free (failure_modify_license_info);
Expand Down
2 changes: 1 addition & 1 deletion src/manage_license.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/* Actions */

int
manage_update_license_file (const char *);
manage_update_license_file (const char *, char **);

int
manage_get_license (char **, theia_license_t **);

0 comments on commit 29c1b98

Please sign in to comment.