1 /* This file is part of Pazpar2.
2 Copyright (C) 2006-2009 Index Data
4 Pazpar2 is free software; you can redistribute it and/or modify it under
5 the terms of the GNU General Public License as published by the Free
6 Software Foundation; either version 2, or (at your option) any later
9 Pazpar2 is distributed in the hope that it will be useful, but WITHOUT ANY
10 WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <yaz/yaz-util.h>
29 //#define CONFIG_NOEXTERNS
30 #include "pazpar2_config.h"
35 union data_types * data_types_assign(NMEM nmem,
36 union data_types ** data1,
37 union data_types data2)
48 *data1 = nmem_malloc(nmem, sizeof(union data_types));
56 struct record * record_create(NMEM nmem, int num_metadata, int num_sortkeys,
57 struct client *client, int position)
59 struct record * record = 0;
64 record = nmem_malloc(nmem, sizeof(struct record));
67 record->client = client;
71 sizeof(struct record_metadata*) * num_metadata);
72 for (i = 0; i < num_metadata; i++)
73 record->metadata[i] = 0;
77 sizeof(union data_types*) * num_sortkeys);
78 for (i = 0; i < num_sortkeys; i++)
79 record->sortkeys[i] = 0;
81 record->position = position;
86 struct record_metadata * record_metadata_create(NMEM nmem)
88 struct record_metadata * rec_md
89 = nmem_malloc(nmem, sizeof(struct record_metadata));
95 struct record_metadata * record_metadata_insert(NMEM nmem,
96 struct record_metadata ** rmd,
97 union data_types data)
99 struct record_metadata * tmp_rmd = 0;
105 // construct new record_metadata
106 tmp_rmd = nmem_malloc(nmem, sizeof(struct record_metadata));
107 tmp_rmd->data = data;
110 // insert in *rmd's place, moving *rmd one down the list
111 tmp_rmd->next = *rmd;
117 struct record_metadata * record_add_metadata_field_id(NMEM nmem,
118 struct record * record,
120 union data_types data)
122 if (field_id < 0 || !record || !record->metadata)
125 return record_metadata_insert(nmem, &(record->metadata[field_id]), data);
129 struct record_metadata * record_add_metadata(NMEM nmem,
130 struct record * record,
131 struct conf_service * service,
133 union data_types data)
137 if (!record || !record->metadata || !service || !name)
140 field_id = conf_service_metadata_field_id(service, name);
145 return record_metadata_insert(nmem, &(record->metadata[field_id]), data);
153 union data_types * record_assign_sortkey_field_id(NMEM nmem,
154 struct record * record,
156 union data_types data)
158 if (field_id < 0 || !record || !record->sortkeys)
161 return data_types_assign(nmem, &(record->sortkeys[field_id]), data);
166 union data_types * record_assign_sortkey(NMEM nmem,
167 struct record * record,
168 struct conf_service * service,
170 union data_types data)
174 if (!record || !service || !name)
177 field_id = conf_service_sortkey_field_id(service, name);
179 if (!(-1 < field_id) || !(field_id < service->num_sortkeys))
182 return record_assign_sortkey_field_id(nmem, record, field_id, data);
190 * c-file-style: "Stroustrup"
191 * indent-tabs-mode: nil
193 * vim: shiftwidth=4 tabstop=8 expandtab