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
|
/* This file is part of GNU Dico.
Copyright (C) 1998-2018 Sergey Poznyakoff
GNU Dico 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, or (at your option)
any later version.
GNU Dico 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 GNU Dico. If not, see <http://www.gnu.org/licenses/>. */
#include <dicod.h>
enum {
DBRF_NONE = 0,
DBRF_RCOUNT = 0x01,
DBRF_CCOUNT = 0x02
};
dicod_db_result_t *
dicod_db_result_alloc(dicod_database_t *db, dico_result_t res)
{
dicod_db_result_t *dbr;
if (!res)
return NULL;
dbr = xmalloc(sizeof(*dbr));
dbr->flags = DBRF_NONE;
dbr->db = db;
dbr->res = res;
return dbr;
}
static inline struct dico_database_module *
dicod_db_result_module(dicod_db_result_t *dbr)
{
return dbr->db->instance->module;
}
void
dicod_db_result_free(dicod_db_result_t *dbr)
{
dicod_db_result_module(dbr)->dico_free_result(dbr->res);
free(dbr);
}
size_t
dicod_db_result_count(dicod_db_result_t *dbr)
{
if (!(dbr->flags & DBRF_RCOUNT)) {
dbr->rcount = dicod_db_result_module(dbr)->dico_result_count(dbr->res);
dbr->flags |= DBRF_RCOUNT;
}
return dbr->rcount;
}
size_t
dicod_db_result_compare_count(dicod_db_result_t *dbr)
{
if (!(dbr->flags & DBRF_CCOUNT)) {
dbr->ccount = dicod_db_result_module(dbr)->dico_compare_count(dbr->res);
dbr->flags |= DBRF_CCOUNT;
}
return dbr->ccount;
}
int
dicod_db_result_output(dicod_db_result_t *dbr, size_t n, dico_stream_t str)
{
return dicod_db_result_module(dbr)->dico_output_result(dbr->res, n, str);
}
dico_assoc_list_t
dicod_db_result_mime_header(dicod_db_result_t *dbr, size_t n)
{
dico_assoc_list_t hdr = NULL;
struct dico_database_module *mod = dicod_db_result_module(dbr);
dicod_database_t *db = dicod_db_result_db(dbr, n, result_db_all);
if (db->mime_headers)
hdr = dico_assoc_dup(db->mime_headers);
else
dico_header_parse(&hdr, NULL);
if (mod->dico_result_headers) {
dico_assoc_list_t tmp = dico_assoc_dup(hdr);
if (mod->dico_result_headers(dbr->res, tmp) == 0) {
dico_assoc_destroy(&hdr);
hdr = tmp;
} else {
dico_assoc_destroy(&tmp);
}
}
return hdr;
}
dicod_database_t *
dicod_db_result_db(dicod_db_result_t *dbr, size_t n, int flag)
{
dicod_database_t *db = NULL;
struct dico_database_module *mod = dicod_db_result_module(dbr);
if (mod->dico_result_db) {
db = mod->dico_result_db(dbr->res, n);
if (db && flag == result_db_visible && !database_is_visible(db))
db = dbr->db;
}
return db ? db : dbr->db;
}
|