summaryrefslogtreecommitdiff
path: root/src/analysis/db/collection.h
blob: b40082035a1e9b62b6ac15414cc3937ccbd3f4f4 (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

/* Chrysalide - Outil d'analyse de fichiers binaires
 * collection.h - prototypes pour la gestion d'éléments ajoutés par collection
 *
 * Copyright (C) 2014 Cyrille Bagard
 *
 *  This file is part of Chrysalide.
 *
 *  OpenIDA 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.
 *
 *  OpenIDA 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/>.
 */


#ifndef _ANALYSIS_DB_COLLECTION_H
#define _ANALYSIS_DB_COLLECTION_H


#include <glib-object.h>
#include <sqlite3.h>
#include <stdbool.h>
#include <stdint.h>


#include "item.h"
#include "protocol.h"



#define G_TYPE_DB_COLLECTION               g_db_collection_get_type()
#define G_DB_COLLECTION(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj), g_db_collection_get_type(), GDbCollection))
#define G_IS_DB_COLLECTION(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj), g_db_collection_get_type()))
#define G_DB_COLLECTION_GET_IFACE(inst)    (G_TYPE_INSTANCE_GET_INTERFACE((inst), g_db_collection_get_type(), GDbCollectionIface))
#define G_DB_COLLECTION_GET_CLASS(obj)     (G_TYPE_INSTANCE_GET_CLASS((obj), G_TYPE_DB_COLLECTION, GDbCollectionClass))


/* Collection générique d'éléments (instance) */
typedef struct _GDbCollection GDbCollection;

/* Collection générique d'éléments (classe) */
typedef struct _GDbCollectionClass GDbCollectionClass;


/* Indique le type défini pour une collection générique d'éléments. */
GType g_db_collection_get_type(void);

/* Prépare la mise en place d'une nouvelle collection. */
GDbCollection *g_db_collection_new(uint32_t, GType, const char *);



/* Décrit le type des éléments rassemblées dans une collection. */
uint32_t g_db_collection_get_feature(const GDbCollection *);




/* Réceptionne et traite une requête réseau pour collection. */
bool g_db_collection_recv(GDbCollection *, int, sqlite3 *);

/* Envoie pour traitement une requête réseau pour collection. */
bool g_db_collection_send(GDbCollection *, int, DBAction, GDbItem *);






/* Met à disposition un encadrement des accès aux éléments. */
void g_db_collection_lock_unlock(GDbCollection *, bool, bool);


#define g_db_collection_wlock(col) g_db_collection_lock_unlock(col, true, true);
#define g_db_collection_wunlock(col) g_db_collection_lock_unlock(col, true, false);

#define g_db_collection_rlock(col) g_db_collection_lock_unlock(col, false, true);
#define g_db_collection_runlock(col) g_db_collection_lock_unlock(col, false, false);


/* Renvoie la liste des éléments rassemblés. */
GList *g_db_collection_list_items(const GDbCollection *);




/* Procède à l'ajout d'un nouvel élément dans la collection. */
bool g_db_collection_add_item(GDbCollection *, GDbItem *);

/* Procède à la modification d'un élément dans la collection. */
bool g_db_collection_modify_item(GDbCollection *, GDbItem *);





/* ------------------- CREATION DE L'ABSTRACTION POUR COLLECTIONS ------------------- */


/* Recherche une collection correspondant à un type donné. */
GDbCollection *find_collection_in_list(GList *, uint32_t);



#endif  /* _ANALYSIS_DB_COLLECTION_H */