diff options
Diffstat (limited to 'src/analysis/db/client.c')
-rw-r--r-- | src/analysis/db/client.c | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/src/analysis/db/client.c b/src/analysis/db/client.c index 15ec27f..9558f85 100644 --- a/src/analysis/db/client.c +++ b/src/analysis/db/client.c @@ -92,6 +92,11 @@ struct _GHubClientClass { GObjectClass parent; /* A laisser en premier */ + /* Signaux */ + + void (* snapshots_updated) (GHubClient *); + void (* snapshot_changed) (GHubClient *); + }; @@ -152,6 +157,22 @@ static void g_hub_client_class_init(GHubClientClass *klass) object->dispose = (GObjectFinalizeFunc/* ! */)g_hub_client_dispose; object->finalize = (GObjectFinalizeFunc)g_hub_client_finalize; + g_signal_new("snapshots-updated", + G_TYPE_HUB_CLIENT, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(GHubClientClass, snapshots_updated), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + + g_signal_new("snapshot-changed", + G_TYPE_HUB_CLIENT, + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET(GHubClientClass, snapshot_changed), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + } @@ -188,6 +209,7 @@ static void g_hub_client_init(GHubClient *client) client->snap_count = 0; g_mutex_init(&client->snap_lock); + setup_empty_snapshot_id(&client->current); client->has_current = false; g_mutex_init(&client->cur_lock); @@ -857,6 +879,12 @@ static void *g_hub_client_update(GHubClient *client) client->can_get_updates = (tmp8 == 0x1); break; + case DBC_GET_SNAPSHOTS: + log_variadic_message(LMT_INFO, + _("This command is not available on this side: 0x%08x"), command); + goto gdcu_bad_exchange; + break; + case DBC_SNAPSHOTS_UPDATED: status = g_hub_client_update_snapshots(client, &in_pbuf); @@ -878,6 +906,8 @@ static void *g_hub_client_update(GHubClient *client) break; case DBC_SET_CUR_SNAPSHOT: + case DBC_SET_SNAPSHOT_NAME: + case DBC_SET_SNAPSHOT_DESC: log_variadic_message(LMT_INFO, _("This command is not available on this side: 0x%08x"), command); goto gdcu_bad_exchange; @@ -987,6 +1017,9 @@ static bool g_hub_client_update_snapshots(GHubClient *client, packed_buffer *pbu g_mutex_unlock(&client->snap_lock); + if (result) + g_signal_emit_by_name(client, "snapshots-updated"); + return result; } @@ -1023,6 +1056,8 @@ static bool g_hub_client_update_current_snapshot(GHubClient *client, packed_buff g_mutex_unlock(&client->cur_lock); + g_signal_emit_by_name(client, "snapshot-changed"); + } return result; @@ -1416,3 +1451,121 @@ bool g_hub_client_set_current_snapshot(GHubClient *client, const snapshot_id_t * return result; } + + +/****************************************************************************** +* * +* Paramètres : client = client pour les accès distants à manipuler. * +* id = identifiant d'instantané à traiter. * +* name = désignation humaine pour l'instantané. * +* * +* Description : Définit la désignation d'un instantané donné. * +* * +* Retour : true si la commande a bien été envoyée, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool g_hub_client_set_snapshot_name(GHubClient *client, const snapshot_id_t *id, const char *name) +{ + bool result; /* Bilan partiel à remonter */ + packed_buffer out_pbuf; /* Tampon d'émission */ + SSL *tls_fd; /* Canal de communication SSL */ + rle_string string; /* Chaîne à transmettre */ + + init_packed_buffer(&out_pbuf); + + tls_fd = g_hub_client_get_ssl_fd(client); + + if (tls_fd == NULL) + result = false; + + else + { + result = extend_packed_buffer(&out_pbuf, (uint32_t []) { DBC_SET_SNAPSHOT_NAME }, sizeof(uint32_t), true); + + if (result) + result = pack_snapshot_id(id, &out_pbuf); + + if (result) + { + init_static_rle_string(&string, name); + + result = pack_rle_string(&string, &out_pbuf); + + exit_rle_string(&string); + + } + + if (result) + result = ssl_send_packed_buffer(&out_pbuf, tls_fd); + + g_hub_client_put_ssl_fd(client, tls_fd); + + } + + exit_packed_buffer(&out_pbuf); + + return result; + +} + + +/****************************************************************************** +* * +* Paramètres : client = client pour les accès distants à manipuler. * +* id = identifiant d'instantané à traiter. * +* desc = description humaine pour l'instantané. * +* * +* Description : Définit la description d'un instantané donné. * +* * +* Retour : true si la commande a bien été envoyée, false sinon. * +* * +* Remarques : - * +* * +******************************************************************************/ + +bool g_hub_client_set_snapshot_desc(GHubClient *client, const snapshot_id_t *id, const char *desc) +{ + bool result; /* Bilan partiel à remonter */ + packed_buffer out_pbuf; /* Tampon d'émission */ + SSL *tls_fd; /* Canal de communication SSL */ + rle_string string; /* Chaîne à transmettre */ + + init_packed_buffer(&out_pbuf); + + tls_fd = g_hub_client_get_ssl_fd(client); + + if (tls_fd == NULL) + result = false; + + else + { + result = extend_packed_buffer(&out_pbuf, (uint32_t []) { DBC_SET_SNAPSHOT_DESC }, sizeof(uint32_t), true); + + if (result) + result = pack_snapshot_id(id, &out_pbuf); + + if (result) + { + init_static_rle_string(&string, desc); + + result = pack_rle_string(&string, &out_pbuf); + + exit_rle_string(&string); + + } + + if (result) + result = ssl_send_packed_buffer(&out_pbuf, tls_fd); + + g_hub_client_put_ssl_fd(client, tls_fd); + + } + + exit_packed_buffer(&out_pbuf); + + return result; + +} |