summaryrefslogtreecommitdiff
path: root/src/analysis/db/items/bookmark.c
blob: 0db847b76bd9554569d88a04028b76f9616d8a2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849

/* Chrysalide - Outil d'analyse de fichiers binaires
 * bookmark.c - gestion des signets au sein d'un binaire
 *
 * Copyright (C) 2014-2017 Cyrille Bagard
 *
 *  This file is part of Chrysalide.
 *
 *  Chrysalide is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Chrysalide is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 */


#include "bookmark.h"


#include <stdarg.h>
#include <stdio.h>
#include <sys/socket.h>


#include <i18n.h>


#include "../collection-int.h"
#include "../item-int.h"



/* --------------------- ELABORATION D'UN ELEMENT DE COLLECTION --------------------- */


/* Signet à l'intérieur d'une zone de texte (instance) */
struct _GDbBookmark
{
    GDbItem parent;                         /* A laisser en premier        */

    vmpa2t addr;                            /* Adresse du signet           */
    rle_string comment;                     /* Eventuel commentaire associé*/

    bool prev_state;                        /* Drapeau déjà présent avant ?*/

};

/* Signet à l'intérieur d'une zone de texte (classe) */
struct _GDbBookmarkClass
{
    GDbItemClass parent;                    /* A laisser en premier        */

};


/* Initialise la classe des signets dans une zone de texte. */
static void g_db_bookmark_class_init(GDbBookmarkClass *);

/* Initialise un signet dans une zone de texte. */
static void g_db_bookmark_init(GDbBookmark *);

/* Supprime toutes les références externes. */
static void g_db_bookmark_dispose(GDbBookmark *);

/* Procède à la libération totale de la mémoire. */
static void g_db_bookmark_finalize(GDbBookmark *);

/* Effectue la comparaison entre deux signets de collection. */
static gint g_db_bookmark_cmp(GDbBookmark *, GDbBookmark *, bool);

/* Importe la définition d'un signet dans un flux réseau. */
static bool g_db_bookmark_unpack(GDbBookmark *, packed_buffer *);

/* Exporte la définition d'un signet dans un flux réseau. */
static bool g_db_bookmark_pack(const GDbBookmark *, packed_buffer *);

/* Construit la description humaine d'un signet sur un tampon. */
static void g_db_bookmark_build_label(GDbBookmark *);

/* Exécute un signet sur un tampon de binaire chargé. */
static bool g_db_bookmark_run(GDbBookmark *, GLoadedBinary *, bool *, bool);

/* Applique un signet sur un tampon de binaire chargé. */
static bool g_db_bookmark_apply(GDbBookmark *, GLoadedBinary *);

/* Annule un signet sur un tampon de binaire chargé. */
static bool g_db_bookmark_cancel(GDbBookmark *, GLoadedBinary *);

/* Constitue les champs destinés à une insertion / modification. */
static bool g_db_bookmark_prepare_db_statement(const GDbBookmark *, bound_value **, size_t *);

/* Charge les valeurs utiles pour un signet. */
static bool g_db_bookmark_load(GDbBookmark *, const bound_value *, size_t);



/* ---------------------- DEFINITION DE LA COLLECTION ASSOCIEE ---------------------- */


/* Collection dédiée aux signets (instance) */
struct _GBookmarkCollection
{
    GDbCollection parent;                   /* A laisser en premier        */

};

/* Collection dédiée aux signets (classe) */
struct _GBookmarkCollectionClass
{
    GDbCollectionClass parent;              /* A laisser en premier        */

};


/* Initialise la classe des signets dans une zone de texte. */
static void g_bookmark_collection_class_init(GBookmarkCollectionClass *);

/* Initialise un signet dans une zone de texte. */
static void g_bookmark_collection_init(GBookmarkCollection *);

/* Supprime toutes les références externes. */
static void g_bookmark_collection_dispose(GBookmarkCollection *);

/* Procède à la libération totale de la mémoire. */
static void g_bookmark_collection_finalize(GBookmarkCollection *);

/* Crée la table des signets dans une base de données. */
static bool g_bookmark_collection_create_db_table(const GBookmarkCollection *, sqlite3 *);

/* Décrit les colonnes utiles à un chargement de données. */
static bool g_bookmark_collection_setup_load(GBookmarkCollection *, bound_value **, size_t *);

/* Détermine si un élément est déjà présent ou non. */
static GDbItem *g_bookmark_collection_has_key(GBookmarkCollection *, va_list);



/* ---------------------------------------------------------------------------------- */
/*                       ELABORATION D'UN ELEMENT DE COLLECTION                       */
/* ---------------------------------------------------------------------------------- */


/* Indique le type défini pour un signet à l'intérieur d'une zone de texte. */
G_DEFINE_TYPE(GDbBookmark, g_db_bookmark, G_TYPE_DB_ITEM);


/******************************************************************************
*                                                                             *
*  Paramètres  : klass = classe à initialiser.                                *
*                                                                             *
*  Description : Initialise la classe des signets dans une zone de texte.     *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_db_bookmark_class_init(GDbBookmarkClass *klass)
{
    GObjectClass *object;                   /* Autre version de la classe  */
    GDbItemClass *item;                     /* Encore une autre vision...  */

    object = G_OBJECT_CLASS(klass);

    object->dispose = (GObjectFinalizeFunc/* ! */)g_db_bookmark_dispose;
    object->finalize = (GObjectFinalizeFunc)g_db_bookmark_finalize;

    item = G_DB_ITEM_CLASS(klass);

    item->feature = DBF_BOOKMARKS;

    item->cmp = (cmp_db_item_fc)g_db_bookmark_cmp;

    item->unpack = (unpack_db_item_fc)g_db_bookmark_unpack;
    item->pack = (pack_db_item_fc)g_db_bookmark_pack;

    item->build_label = (build_item_label_fc)g_db_bookmark_build_label;
    item->apply = (run_item_fc)g_db_bookmark_apply;
    item->cancel = (run_item_fc)g_db_bookmark_cancel;

    item->prepare_stmt = (prepare_db_statement)g_db_bookmark_prepare_db_statement;
    item->load = (load_db_item_fc)g_db_bookmark_load;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : bookmark = instance à initialiser.                           *
*                                                                             *
*  Description : Initialise un signet dans une zone de texte.                 *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_db_bookmark_init(GDbBookmark *bookmark)
{

}


/******************************************************************************
*                                                                             *
*  Paramètres  : bookmark = instance d'objet GLib à traiter.                  *
*                                                                             *
*  Description : Supprime toutes les références externes.                     *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_db_bookmark_dispose(GDbBookmark *bookmark)
{
    G_OBJECT_CLASS(g_db_bookmark_parent_class)->dispose(G_OBJECT(bookmark));

}


/******************************************************************************
*                                                                             *
*  Paramètres  : bookmark = instance d'objet GLib à traiter.                  *
*                                                                             *
*  Description : Procède à la libération totale de la mémoire.                *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_db_bookmark_finalize(GDbBookmark *bookmark)
{
    exit_rle_string(&bookmark->comment);

    G_OBJECT_CLASS(g_db_bookmark_parent_class)->finalize(G_OBJECT(bookmark));

}


/******************************************************************************
*                                                                             *
*  Paramètres  : addr    = adresse inamovible localisant une position donnée. *
*                comment = commentaire construit ou NULL.                     *
*                                                                             *
*  Description : Crée une définition d'un signet dans une zone de texte.      *
*                                                                             *
*  Retour      : Signet mis en place ou NULL en cas d'erreur.                 *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

GDbBookmark *g_db_bookmark_new(const vmpa2t *addr, const char *comment)
{
    GDbBookmark *result;                    /* Instance à retourner        */

    result = g_object_new(G_TYPE_DB_BOOKMARK, NULL);

    copy_vmpa(&result->addr, addr);

    g_db_bookmark_set_comment(result, comment);

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : a    = premier élément à analyser.                           *
*                b    = second élément à analyser.                            *
*                with = précise les horodatages à prendre en compte.          *
*                                                                             *
*  Description : Effectue la comparaison entre deux signets de collection.    *
*                                                                             *
*  Retour      : Bilan de la comparaison : -1, 0 ou 1.                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static gint g_db_bookmark_cmp(GDbBookmark *a, GDbBookmark *b, bool with)
{
    gint result;                            /* Bilan de la comparaison     */

    result = cmp_vmpa(&a->addr, &b->addr);

    if (result == 0)
        result = cmp_rle_string(&a->comment, &b->comment);

    if (result == 0)
        result = G_DB_ITEM_CLASS(g_db_bookmark_parent_class)->cmp(G_DB_ITEM(a), G_DB_ITEM(b), with);

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : bookmark = signet dont les informations sont à charger. [OUT]*
*                pbuf     = paquet de données où venir inscrire les infos.    *
*                                                                             *
*  Description : Importe la définition d'un signet dans un flux réseau.       *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static bool g_db_bookmark_unpack(GDbBookmark *bookmark, packed_buffer *pbuf)
{
    bool result;                            /* Bilan à retourner           */

    result = G_DB_ITEM_CLASS(g_db_bookmark_parent_class)->unpack(G_DB_ITEM(bookmark), pbuf);

    if (result)
        result = unpack_vmpa(&bookmark->addr, pbuf);

    if (result)
        result = unpack_rle_string(&bookmark->comment, pbuf);

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : bookmark = informations à sauvegarder.                       *
*                pbuf     = paquet de données où venir inscrire les infos.    *
*                                                                             *
*  Description : Exporte la définition d'un signet dans un flux réseau.       *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static bool g_db_bookmark_pack(const GDbBookmark *bookmark, packed_buffer *pbuf)
{
    bool result;                            /* Bilan à retourner           */

    result = G_DB_ITEM_CLASS(g_db_bookmark_parent_class)->pack(G_DB_ITEM(bookmark), pbuf);

    if (result)
        result = pack_vmpa(&bookmark->addr, pbuf);

    if (result)
        result = pack_rle_string(&bookmark->comment, pbuf);

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : bookmark = signet à manipuler.                               *
*                                                                             *
*  Description : Construit la description humaine d'un signet sur un tampon.  *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_db_bookmark_build_label(GDbBookmark *bookmark)
{
    asprintf(&G_DB_ITEM(bookmark)->label, _("Bookmark \"%s\""), get_rle_string(&bookmark->comment));

}


/******************************************************************************
*                                                                             *
*  Paramètres  : bookmark = signet à manipuler.                               *
*                binary   = binaire chargé en mémoire à modifier.             *
*                prev     = état précédent de la présence du drapeau. [OUT]   *
*                set      = précision quant au nouvel état du drapeau.        *
*                                                                             *
*  Description : Exécute un signet sur un tampon de binaire chargé.           *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static bool g_db_bookmark_run(GDbBookmark *bookmark, GLoadedBinary *binary, bool *prev, bool set)
{
    return false;
#if 0
    bool result;                            /* Bilan à faire remonter      */
    GCodeBuffer *buffer;                    /* Tampon de lignes à traiter  */
    GBufferLine *line;                      /* Ligne de tampon à marquer   */

    result = true;

    buffer = g_loaded_binary_get_disassembled_buffer(binary);

    line = g_code_buffer_find_line_by_addr(buffer, &bookmark->addr, BLF_HAS_CODE, NULL);
    if (line == NULL)
    {
        result = false;
        goto exit;
    }

    *prev = g_buffer_line_get_flags(line) & BLF_BOOKMARK;

    if (set)
        g_buffer_line_add_flag(line, BLF_BOOKMARK);

    else
        g_buffer_line_remove_flag(line, BLF_BOOKMARK);

    g_object_unref(G_OBJECT(line));

 exit:

    return result;
#endif
}


/******************************************************************************
*                                                                             *
*  Paramètres  : bookmark = signet à manipuler.                               *
*                binary   = binaire chargé en mémoire à modifier.             *
*                                                                             *
*  Description : Applique un signet sur un tampon de binaire chargé.          *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static bool g_db_bookmark_apply(GDbBookmark *bookmark, GLoadedBinary *binary)
{
    bool result;                            /* Bilan à faire remonter      */

    result = g_db_bookmark_run(bookmark, binary, &bookmark->prev_state, true);

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : bookmark = signet à manipuler.                               *
*                binary   = binaire chargé en mémoire à modifier.             *
*                                                                             *
*  Description : Annule un signet sur un tampon de binaire chargé.            *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static bool g_db_bookmark_cancel(GDbBookmark *bookmark, GLoadedBinary *binary)
{
    bool result;                            /* Bilan à faire remonter      */

    if (!bookmark->prev_state)
        result = g_db_bookmark_run(bookmark, binary, (bool []) { 0 }, false);
    else
        result = true;

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : bookmark = base d'éléments sur laquelle s'appuyer.           *
*                values   = couples de champs et de valeurs à lier. [OUT]     *
*                count    = nombre de ces couples. [OUT]                      *
*                                                                             *
*  Description : Constitue les champs destinés à une insertion / modification.*
*                                                                             *
*  Retour      : Etat du besoin en sauvegarde.                                *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static bool g_db_bookmark_prepare_db_statement(const GDbBookmark *bookmark, bound_value **values, size_t *count)
{
    bool status;                            /* Bilan d'opération initiale  */

    status = G_DB_ITEM_CLASS(g_db_bookmark_parent_class)->prepare_stmt(G_DB_ITEM(bookmark), values, count);
    if (!status) return false;

    status = prepare_vmpa_db_statement(&bookmark->addr, NULL, values, count);
    if (!status) return false;

    status &= prepare_db_statement_for_rle_string(&bookmark->comment, "comment", values, count);
    if (!status) return false;

    return true;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : bookmark = bascule d'affichage à charger depuis les réponses.*
*                values   = tableau d'éléments à consulter.                   *
*                count    = nombre de descriptions renseignées.               *
*                                                                             *
*  Description : Charge les valeurs utiles pour un signet.                    *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static bool g_db_bookmark_load(GDbBookmark *bookmark, const bound_value *values, size_t count)
{
    bool result;                            /* Bilan à faire remonter      */

    result = G_DB_ITEM_CLASS(g_db_bookmark_parent_class)->load(G_DB_ITEM(bookmark), values, count);

    result &= load_vmpa(&bookmark->addr, NULL, values, count);

    result &= load_rle_string(&bookmark->comment, "comment", values, count);

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : bookmark = informations à consulter.                         *
*                                                                             *
*  Description : Fournit l'adresse associée à un signet.                      *
*                                                                             *
*  Retour      : Adresse mémoire.                                             *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

const vmpa2t *g_db_bookmark_get_address(GDbBookmark *bookmark)
{
    return &bookmark->addr;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : bookmark = informations à consulter.                         *
*                                                                             *
*  Description : Fournit le commentaire associé à un signet.                  *
*                                                                             *
*  Retour      : Commentaire existant ou NULL.                                *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

const char *g_db_bookmark_get_comment(const GDbBookmark *bookmark)
{
    return get_rle_string(&bookmark->comment);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : bookmark = informations à consulter.                         *
*                comment  = commentaire construit ou NULL.                    *
*                                                                             *
*  Description : Définit le commentaire associé à un signet.                  *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

void g_db_bookmark_set_comment(GDbBookmark *bookmark, const char *comment)
{
    dup_into_rle_string(&bookmark->comment, comment);

}



/* ---------------------------------------------------------------------------------- */
/*                        DEFINITION DE LA COLLECTION ASSOCIEE                        */
/* ---------------------------------------------------------------------------------- */


/* Indique le type défini pour une collection de signets. */
G_DEFINE_TYPE(GBookmarkCollection, g_bookmark_collection, G_TYPE_DB_COLLECTION);


/******************************************************************************
*                                                                             *
*  Paramètres  : klass = classe à initialiser.                                *
*                                                                             *
*  Description : Initialise la classe des signets dans une zone de texte.     *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_bookmark_collection_class_init(GBookmarkCollectionClass *klass)
{
    GObjectClass *object;                   /* Autre version de la classe  */
    GDbCollectionClass *collec;             /* Encore une autre vision...  */

    object = G_OBJECT_CLASS(klass);

    object->dispose = (GObjectFinalizeFunc/* ! */)g_bookmark_collection_dispose;
    object->finalize = (GObjectFinalizeFunc)g_bookmark_collection_finalize;

    collec = G_DB_COLLECTION_CLASS(klass);

    collec->create_table = (collec_create_db_table_fc)g_bookmark_collection_create_db_table;
    collec->setup_load = (collec_setup_load_fc)g_bookmark_collection_setup_load;
    collec->has_key = (collec_has_key_fc)g_bookmark_collection_has_key;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : collec = instance à initialiser.                             *
*                                                                             *
*  Description : Initialise un signet dans une zone de texte.                 *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_bookmark_collection_init(GBookmarkCollection *collec)
{
    G_DB_COLLECTION(collec)->featuring = DBF_BOOKMARKS;
    G_DB_COLLECTION(collec)->type = G_TYPE_DB_BOOKMARK;
    G_DB_COLLECTION(collec)->name = "Bookmarks";

}


/******************************************************************************
*                                                                             *
*  Paramètres  : collec = instance d'objet GLib à traiter.                    *
*                                                                             *
*  Description : Supprime toutes les références externes.                     *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_bookmark_collection_dispose(GBookmarkCollection *collec)
{
    G_OBJECT_CLASS(g_bookmark_collection_parent_class)->dispose(G_OBJECT(collec));

}


/******************************************************************************
*                                                                             *
*  Paramètres  : collec = instance d'objet GLib à traiter.                    *
*                                                                             *
*  Description : Procède à la libération totale de la mémoire.                *
*                                                                             *
*  Retour      : -                                                            *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static void g_bookmark_collection_finalize(GBookmarkCollection *collec)
{
    G_OBJECT_CLASS(g_bookmark_collection_parent_class)->finalize(G_OBJECT(collec));

}


/******************************************************************************
*                                                                             *
*  Paramètres  : -                                                            *
*                                                                             *
*  Description : Crée une collection dédiée aux signets.                      *
*                                                                             *
*  Retour      : Collection mise en place.                                    *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

GBookmarkCollection *g_bookmark_collection_new(void)
{
    GBookmarkCollection *result;            /* Instance à retourner        */

    result = g_object_new(G_TYPE_BM_COLLECTION, NULL);

    return result;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : collec = ensemble d'éléments spectateur des opérations.      *
*                db     = accès à la base de données.                         *
*                                                                             *
*  Description : Crée la table des signets dans une base de données.          *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static bool g_bookmark_collection_create_db_table(const GBookmarkCollection *collec, sqlite3 *db)
{
    char *sql;                              /* Requête à exécuter          */
    int ret;                                /* Bilan de la création        */
    char *msg;                              /* Message d'erreur            */

    sql = "CREATE TABLE Bookmarks ("            \
             SQLITE_DB_ITEM_CREATE ", "         \
             SQLITE_SIMPLE_VMPA_CREATE ", "     \
             SQLITE_RLESTR_CREATE("comment")    \
          ");";

    ret = sqlite3_exec(db, sql, NULL, NULL, &msg);
    if (ret != SQLITE_OK)
    {
        fprintf(stderr, "sqlite3_exec(): %s\n", msg);
        sqlite3_free(msg);
    }

    return (ret == SQLITE_OK);

}


/******************************************************************************
*                                                                             *
*  Paramètres  : collec = ensemble d'éléments à consulter.                    *
*                values = tableau d'éléments à compléter. [OUT]               *
*                count  = nombre de descriptions renseignées. [OUT]           *
*                                                                             *
*  Description : Décrit les colonnes utiles à un chargement de données.       *
*                                                                             *
*  Retour      : Bilan de l'opération.                                        *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static bool g_bookmark_collection_setup_load(GBookmarkCollection *collec, bound_value **values, size_t *count)
{
    bool status;                            /* Bilan d'une préparation     */

    status = G_DB_COLLECTION_CLASS(g_bookmark_collection_parent_class)->setup_load(G_DB_COLLECTION(collec), \
                                                                                   values, count);
    if (!status) return false;

    if (!setup_load_for_vmpa(NULL, NULL, values, count))
        return false;

    if (!setup_load_of_rle_string(NULL, "comment", values, count))
        return false;

    return true;

}


/******************************************************************************
*                                                                             *
*  Paramètres  : collec = ensemble d'éléments à consulter.                    *
*                ap     = clef identifiant de manière unique un élément.      *
*                                                                             *
*  Description : Détermine si un élément est déjà présent ou non.             *
*                                                                             *
*  Retour      : Elément trouvé ou NULL si aucun.                             *
*                                                                             *
*  Remarques   : -                                                            *
*                                                                             *
******************************************************************************/

static GDbItem *g_bookmark_collection_has_key(GBookmarkCollection *collec, va_list ap)
{
    GDbItem *result;                        /* Bilan à retourner           */
    vmpa2t *ref;                            /* Adresse de référence        */
    GList *items;                           /* Eléments déjà en place      */
    GList *iter;                            /* Boucle de parcours          */
    GDbBookmark *bm;                        /* Signet à consulter          */

    result = NULL;

    ref = va_arg(ap, vmpa2t *);

    items = g_db_collection_list_items(G_DB_COLLECTION(collec));

    for (iter = g_list_first(items); iter != NULL && result == NULL; iter = g_list_next(iter))
    {
        bm = G_DB_BOOKMARK(iter->data);

        if (cmp_vmpa(&bm->addr, ref) != 0)

            /**
             * Un verrou est sensé être posé, donc il n'y a pas besoin
             * de toucher au décompte des références car l'élément trouvé
             * ne peut pas être supprimé.
             */
            result = G_DB_ITEM(bm);

    }

    return result;

}