1 /* This file is part of Pazpar2.
2 Copyright (C) 2006-2010 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 #include "pazpar2_config.h"
32 union data_types * data_types_assign(NMEM nmem,
33 union data_types ** data1,
34 union data_types data2)
45 *data1 = nmem_malloc(nmem, sizeof(union data_types));
53 struct record * record_create(NMEM nmem, int num_metadata, int num_sortkeys,
54 struct client *client, int position)
56 struct record * record = 0;
61 record = nmem_malloc(nmem, sizeof(struct record));
64 record->client = client;
68 sizeof(struct record_metadata*) * num_metadata);
69 for (i = 0; i < num_metadata; i++)
70 record->metadata[i] = 0;
74 sizeof(union data_types*) * num_sortkeys);
75 for (i = 0; i < num_sortkeys; i++)
76 record->sortkeys[i] = 0;
78 record->position = position;
83 struct record_metadata * record_metadata_create(NMEM nmem)
85 struct record_metadata * rec_md
86 = nmem_malloc(nmem, sizeof(struct record_metadata));
88 rec_md->attributes = 0;
93 struct record_metadata * record_metadata_insert(NMEM nmem,
94 struct record_metadata ** rmd,
95 union data_types data)
97 struct record_metadata * tmp_rmd = 0;
103 // construct new record_metadata
104 tmp_rmd = nmem_malloc(nmem, sizeof(struct record_metadata));
105 tmp_rmd->data = data;
108 // insert in *rmd's place, moving *rmd one down the list
109 tmp_rmd->next = *rmd;
115 struct record_metadata * record_add_metadata_field_id(NMEM nmem,
116 struct record * record,
118 union data_types data)
120 if (field_id < 0 || !record || !record->metadata)
123 return record_metadata_insert(nmem, &(record->metadata[field_id]), data);
127 struct record_metadata * record_add_metadata(NMEM nmem,
128 struct record * record,
129 struct conf_service * service,
131 union data_types data)
135 if (!record || !record->metadata || !service || !name)
138 field_id = conf_service_metadata_field_id(service, name);
143 return record_metadata_insert(nmem, &(record->metadata[field_id]), data);
151 union data_types * record_assign_sortkey_field_id(NMEM nmem,
152 struct record * record,
154 union data_types data)
156 if (field_id < 0 || !record || !record->sortkeys)
159 return data_types_assign(nmem, &(record->sortkeys[field_id]), data);
164 union data_types * record_assign_sortkey(NMEM nmem,
165 struct record * record,
166 struct conf_service * service,
168 union data_types data)
172 if (!record || !service || !name)
175 field_id = conf_service_sortkey_field_id(service, name);
177 if (!(-1 < field_id) || !(field_id < service->num_sortkeys))
180 return record_assign_sortkey_field_id(nmem, record, field_id, data);
188 * c-file-style: "Stroustrup"
189 * indent-tabs-mode: nil
191 * vim: shiftwidth=4 tabstop=8 expandtab