2 * Copyright (C) 2011 Sansar Choinyambuu
3 * HSR Hochschule fuer Technik Rapperswil
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 #include "pts_database.h"
19 #include <crypto/hashers/hasher.h>
22 typedef struct private_pts_database_t private_pts_database_t
;
25 * Private data of a pts_database_t object.
28 struct private_pts_database_t
{
31 * Public pts_database_t interface.
33 pts_database_t
public;
42 METHOD(pts_database_t
, create_file_enumerator
, enumerator_t
*,
43 private_pts_database_t
*this, char *product
)
47 /* look for all entries belonging to a product in the files table */
48 e
= this->db
->query(this->db
,
49 "SELECT f.id, f.type, f.path FROM files AS f "
50 "JOIN product_file AS pf ON f.id = pf.file "
51 "JOIN products AS p ON p.id = pf.product "
53 DB_TEXT
, product
, DB_INT
, DB_INT
, DB_TEXT
);
57 METHOD(pts_database_t
, create_hash_enumerator
, enumerator_t
*,
58 private_pts_database_t
*this, char *product
, pts_meas_algorithms_t algo
,
65 e
= this->db
->query(this->db
,
66 "SELECT f.path, fh.hash FROM file_hashes AS fh "
67 "JOIN files AS f ON fh.file = f.id "
68 "JOIN products AS p ON fh.product = p.id "
69 "WHERE p.name = ? AND fh.directory = ? AND fh.algo = ? "
71 DB_TEXT
, product
, DB_INT
, id
, DB_INT
, algo
, DB_TEXT
, DB_BLOB
);
75 e
= this->db
->query(this->db
,
76 "SELECT f.path, fh.hash FROM file_hashes AS fh "
77 "JOIN files AS f ON fh.file = f.id "
78 "JOIN products AS p ON fh.product = p.id "
79 "WHERE p.name = ? AND fh.file = ? AND fh.algo = ?",
80 DB_TEXT
, product
, DB_INT
, id
, DB_INT
, algo
, DB_TEXT
, DB_BLOB
);
85 METHOD(pts_database_t
, destroy
, void,
86 private_pts_database_t
*this)
88 this->db
->destroy(this->db
);
95 pts_database_t
*pts_database_create(char *uri
)
97 private_pts_database_t
*this;
101 .create_file_enumerator
= _create_file_enumerator
,
102 .create_hash_enumerator
= _create_hash_enumerator
,
105 .db
= lib
->db
->create(lib
->db
, uri
),
110 DBG1(DBG_TNC
, "failed to connect to PTS file measurement database '%s'",
116 return &this->public;