Skip to content

Commit

Permalink
[agroal#392] Add application name and version in management protocol
Browse files Browse the repository at this point in the history
In order to improve debugging, [agroal#392] suggested to write
the sender application name and its version in the
socket over which pgagroal-cli and pgagroal communicate.

Introduces the 'write_info' function in management.c.
  • Loading branch information
EuGig committed Apr 24, 2024
1 parent 5dd618b commit b8d633d
Show file tree
Hide file tree
Showing 5 changed files with 320 additions and 19 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Yongting You <2010youy01@gmail.com>
Ashutosh Sharma <ash2003sharma@gmail.com>
Henrique de Carvalho <decarv.henrique@gmail.com>
Yihe Lu <t1t4m1un@gmail.com>
Eugenio Gigante <giganteeugenio2@gmail.com>
2 changes: 1 addition & 1 deletion src/include/json.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
* response object
*/
cJSON*
pgagroal_json_create_new_command_object(char* command_name, bool success, char* executable_name);
pgagroal_json_create_new_command_object(char* command_name, bool success, char* executable_name, char* executable_version);

/**
* Utility method to "jump" to the output JSON object wrapped into
Expand Down
19 changes: 19 additions & 0 deletions src/include/management.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@ extern "C" {
#define COMMAND_OUTPUT_FORMAT_TEXT 'T'
#define COMMAND_OUTPUT_FORMAT_JSON 'J'

/**
* Available applications
*/
#define PGAGROAL_EXECUTABLE 1
#define PGAGROAL_EXECUTABLE_CLI 2
#define PGAGROAL_EXECUTABLE_VAULT 3

/*
* stores the application name and its version
* which are sent through the socket
*/
struct pgagroal_version_info
{
char s[2];
int command;
char v[3];
int version;
};

/**
* Get the frontend password of a user
* @param ssl The SSL connection
Expand Down
10 changes: 5 additions & 5 deletions src/libpgagroal/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include <json.h>

cJSON*
pgagroal_json_create_new_command_object(char* command_name, bool success, char* executable_name)
pgagroal_json_create_new_command_object(char* command_name, bool success, char* executable_name, char* executable_version)
{
// root of the JSON structure
cJSON* json = cJSON_CreateObject();
Expand Down Expand Up @@ -71,10 +71,10 @@ pgagroal_json_create_new_command_object(char* command_name, bool success, char*
}

cJSON_AddStringToObject(application, JSON_TAG_APPLICATION_NAME, executable_name);
cJSON_AddNumberToObject(application, JSON_TAG_APPLICATION_VERSION_MAJOR, PGAGROAL_MAJOR_VERSION);
cJSON_AddNumberToObject(application, JSON_TAG_APPLICATION_VERSION_MINOR, PGAGROAL_MINOR_VERSION);
cJSON_AddNumberToObject(application, JSON_TAG_APPLICATION_VERSION_PATCH, PGAGROAL_PATCH_VERSION);
cJSON_AddStringToObject(application, JSON_TAG_APPLICATION_VERSION, PGAGROAL_VERSION);
cJSON_AddNumberToObject(application, JSON_TAG_APPLICATION_VERSION_MAJOR, executable_version[0] - '0');
cJSON_AddNumberToObject(application, JSON_TAG_APPLICATION_VERSION_MINOR, executable_version[2] - '0');
cJSON_AddNumberToObject(application, JSON_TAG_APPLICATION_VERSION_PATCH, executable_version[4] - '0');
cJSON_AddStringToObject(application, JSON_TAG_APPLICATION_VERSION, executable_version);

// add objects to the whole json thing
cJSON_AddItemToObject(json, "command", command);
Expand Down
Loading

0 comments on commit b8d633d

Please sign in to comment.