~ubuntu-branches/ubuntu/utopic/libuser/utopic-proposed

« back to all changes in this revision

Viewing changes to lib/entity.c

  • Committer: Bazaar Package Importer
  • Author(s): Ghe Rivero
  • Date: 2005-09-30 16:22:04 UTC
  • Revision ID: james.westby@ubuntu.com-20050930162204-qubxaa7e2lbovdgh
Tags: upstream-0.54.dfsg.1
ImportĀ upstreamĀ versionĀ 0.54.dfsg.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2000-2002, 2004, 2005 Red Hat, Inc.
 
3
 *
 
4
 * This is free software; you can redistribute it and/or modify it under
 
5
 * the terms of the GNU Library General Public License as published by
 
6
 * the Free Software Foundation; either version 2 of the License, or
 
7
 * (at your option) any later version.
 
8
 *
 
9
 * This program is distributed in the hope that it will be useful, but
 
10
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Library General Public
 
15
 * License along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
17
 */
 
18
 
 
19
#ident "$Id: entity.c,v 1.30 2005/09/12 23:24:37 mitr Exp $"
 
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#include "../config.h"
 
23
#endif
 
24
#include <grp.h>
 
25
#include <pwd.h>
 
26
#include <stdio.h>
 
27
#include <stdlib.h>
 
28
#include <string.h>
 
29
#include <glib.h>
 
30
#include "user_private.h"
 
31
#include "internal.h"
 
32
 
 
33
/* Create and return a new entity object. */
 
34
struct lu_ent *
 
35
lu_ent_new()
 
36
{
 
37
        struct lu_ent *ent = NULL;
 
38
        ent = g_malloc0(sizeof(struct lu_ent));
 
39
        ent->magic = LU_ENT_MAGIC;
 
40
        ent->cache = lu_string_cache_new(TRUE);
 
41
        ent->current = g_array_new(FALSE, TRUE, sizeof(struct lu_attribute));
 
42
        ent->pending = g_array_new(FALSE, TRUE, sizeof(struct lu_attribute));
 
43
        ent->modules = g_value_array_new(1);
 
44
        return ent;
 
45
}
 
46
 
 
47
struct lu_ent *
 
48
lu_ent_new_typed(enum lu_entity_type entity_type)
 
49
{
 
50
        struct lu_ent *ret;
 
51
        ret = lu_ent_new();
 
52
        ret->type = entity_type;
 
53
        return ret;
 
54
}
 
55
 
 
56
/* Free an entity object. */
 
57
void
 
58
lu_ent_free(struct lu_ent *ent)
 
59
{
 
60
        size_t i;
 
61
        struct lu_attribute *attr;
 
62
        g_return_if_fail(ent != NULL);
 
63
        g_return_if_fail(ent->magic == LU_ENT_MAGIC);
 
64
        /* Free the cache. */
 
65
        ent->cache->free(ent->cache);
 
66
        /* Free each current attribute. */
 
67
        for (i = 0; i < ent->current->len; i++) {
 
68
                attr = &g_array_index(ent->current, struct lu_attribute, i);
 
69
                /* Free the values array in this attribute; the array free
 
70
                 * will get the rest. */
 
71
                g_value_array_free(attr->values);
 
72
                attr->name = 0;
 
73
                attr->values = NULL;
 
74
        }
 
75
        g_array_free(ent->current, TRUE);
 
76
        /* Free each pending attribute. */
 
77
        for (i = 0; i < ent->pending->len; i++) {
 
78
                attr = &g_array_index(ent->pending, struct lu_attribute, i);
 
79
                /* Free the values array in this attribute; the array free
 
80
                 * will get the rest. */
 
81
                g_value_array_free(attr->values);
 
82
                attr->name = 0;
 
83
                attr->values = NULL;
 
84
        }
 
85
        g_array_free(ent->pending, TRUE);
 
86
        /* Free the module list. */
 
87
        g_value_array_free(ent->modules);
 
88
        memset(ent, 0, sizeof(struct lu_ent));
 
89
        g_free(ent);
 
90
}
 
91
 
 
92
/* Dump the contents of an entity structure.  This is primarily for
 
93
 * debugging. */
 
94
void
 
95
lu_ent_dump(struct lu_ent *ent, FILE *fp)
 
96
{
 
97
        size_t i, j;
 
98
        struct lu_attribute *attribute;
 
99
        GValue *value;
 
100
        g_return_if_fail(ent != NULL);
 
101
        fprintf(fp, "dump of struct lu_ent at %p:\n", ent);
 
102
        fprintf(fp, " magic = %08x\n", ent->magic);
 
103
        g_return_if_fail(ent->magic == LU_ENT_MAGIC);
 
104
        g_return_if_fail((ent->type == lu_user) || (ent->type == lu_group));
 
105
        switch (ent->type) {
 
106
                case lu_invalid:
 
107
                        fprintf(fp, " type = invalid\n");
 
108
                        break;
 
109
                case lu_user:
 
110
                        fprintf(fp, " type = user\n");
 
111
                        break;
 
112
                case lu_group:
 
113
                        fprintf(fp, " type = group\n");
 
114
                        break;
 
115
                default:
 
116
                        fprintf(fp, " type = UNKNOWN\n");
 
117
                        break;
 
118
        }
 
119
        /* Print the module list. */
 
120
        fprintf(fp, " modules = (");
 
121
        for (i = 0; i < ent->modules->n_values; i++) {
 
122
                value = g_value_array_get_nth(ent->modules, i);
 
123
                if (i > 0) {
 
124
                        fprintf(fp, ", ");
 
125
                }
 
126
                if (G_VALUE_HOLDS_STRING(value))
 
127
                        fprintf(fp, "`%s'", g_value_get_string(value));
 
128
                else if (G_VALUE_HOLDS_LONG(value))
 
129
                        fprintf(fp, "%ld", g_value_get_long(value));
 
130
                else if (G_VALUE_HOLDS_INT64(value))
 
131
                        fprintf(fp, "%lld",
 
132
                                (long long)g_value_get_int64(value));
 
133
                else
 
134
                        fprintf(fp, "?");
 
135
        }
 
136
        fprintf(fp, ")\n");
 
137
        /* Print the current data values. */
 
138
        for (i = 0; i < ent->current->len; i++) {
 
139
                attribute = &g_array_index(ent->current,
 
140
                                           struct lu_attribute,
 
141
                                           i);
 
142
                for (j = 0; j < attribute->values->n_values; j++) {
 
143
                        value = g_value_array_get_nth(attribute->values, j);
 
144
                        if (G_VALUE_HOLDS_STRING(value))
 
145
                                fprintf(fp, " %s = `%s'\n",
 
146
                                        g_quark_to_string(attribute->name),
 
147
                                        g_value_get_string(value));
 
148
                        else if (G_VALUE_HOLDS_LONG(value))
 
149
                                fprintf(fp, " %s = %ld\n",
 
150
                                        g_quark_to_string(attribute->name),
 
151
                                        g_value_get_long(value));
 
152
 
 
153
                        else if (G_VALUE_HOLDS_INT64(value))
 
154
                                fprintf(fp, " %s = %lld\n",
 
155
                                        g_quark_to_string(attribute->name),
 
156
                                        (long long)g_value_get_int64(value));
 
157
 
 
158
                }
 
159
        }
 
160
        fprintf(fp, "\n");
 
161
        for (i = 0; i < ent->pending->len; i++) {
 
162
                attribute = &g_array_index(ent->pending,
 
163
                                           struct lu_attribute,
 
164
                                           i);
 
165
                for (j = 0; j < attribute->values->n_values; j++) {
 
166
                        value = g_value_array_get_nth(attribute->values, j);
 
167
                        if (G_VALUE_HOLDS_STRING(value))
 
168
                                fprintf(fp, " %s = `%s'\n",
 
169
                                        g_quark_to_string(attribute->name),
 
170
                                        g_value_get_string(value));
 
171
                        else if (G_VALUE_HOLDS_LONG(value))
 
172
                                fprintf(fp, " %s = %ld\n",
 
173
                                        g_quark_to_string(attribute->name),
 
174
                                        g_value_get_long(value));
 
175
                        else if (G_VALUE_HOLDS_INT64(value))
 
176
                                fprintf(fp, " %s = %lld\n",
 
177
                                        g_quark_to_string(attribute->name),
 
178
                                        (long long)g_value_get_int64(value));
 
179
                }
 
180
        }
 
181
}
 
182
 
 
183
/* Add a module to the list of modules kept for this entity. */
 
184
void
 
185
lu_ent_add_module(struct lu_ent *ent, const char *source)
 
186
{
 
187
        GValue value, *val;
 
188
        size_t i;
 
189
        g_return_if_fail(ent != NULL);
 
190
        g_return_if_fail(ent->magic == LU_ENT_MAGIC);
 
191
        g_return_if_fail(ent->modules != NULL);
 
192
        /* Initialize a value with the string. */
 
193
        memset(&value, 0, sizeof(value));
 
194
        g_value_init(&value, G_TYPE_STRING);
 
195
        g_value_set_string(&value, source);
 
196
        /* Now scan the array for the value. */
 
197
        for (i = 0; i < ent->modules->n_values; i++) {
 
198
                val = g_value_array_get_nth(ent->modules, i);
 
199
                /* We only add strings, so there had better be only strings
 
200
                 * in this list, otherwise someone is messing with us. */
 
201
                g_assert(G_VALUE_HOLDS_STRING(val));
 
202
                if (strcmp(g_value_get_string(val),
 
203
                           g_value_get_string(&value)) == 0) {
 
204
                        break;
 
205
                }
 
206
        }
 
207
        /* If we fell of the end of the array, then the new value is not
 
208
         * in there, so we should add it. */
 
209
        if (i >= ent->modules->n_values) {
 
210
                g_value_array_append(ent->modules, &value);
 
211
        }
 
212
        g_value_unset(&value);
 
213
}
 
214
 
 
215
/* Clear the list of modules which affect this module, by freeing the array
 
216
 * we use to keep track of them and allocating a new one. */
 
217
void
 
218
lu_ent_clear_modules(struct lu_ent *ent)
 
219
{
 
220
        g_return_if_fail(ent != NULL);
 
221
        g_return_if_fail(ent->magic == LU_ENT_MAGIC);
 
222
        g_value_array_free(ent->modules);
 
223
        ent->modules = g_value_array_new(1);
 
224
}
 
225
 
 
226
/* Remove all attributes from an object.  This function takes the address
 
227
 * of whichever list we want cleared. */
 
228
static void
 
229
clear_attribute_list(GArray *dest)
 
230
{
 
231
        int i;
 
232
        struct lu_attribute *attr;
 
233
        for (i = dest->len - 1; i >= 0; i--) {
 
234
                attr = &g_array_index(dest, struct lu_attribute, i);
 
235
                g_value_array_free(attr->values);
 
236
                attr->values = NULL;
 
237
                g_array_remove_index_fast(dest, i);
 
238
        }
 
239
}
 
240
 
 
241
/* Copy all attributes from source to dest, wiping out whatever was already
 
242
 * in the destination array. */
 
243
static void
 
244
copy_attributes(GArray *source, GArray *dest)
 
245
{
 
246
        size_t i;
 
247
        struct lu_attribute *attr, newattr;
 
248
        /* First, clear the destination list of all attributes. */
 
249
        clear_attribute_list(dest);
 
250
        /* Now copy all of the attributes and their values. */
 
251
        for (i = 0; i < source->len; i++) {
 
252
                attr = &g_array_index(source, struct lu_attribute, i);
 
253
                /* Copy the attribute name, then its values, into the holding
 
254
                 * area. */
 
255
                memset(&newattr, 0, sizeof(newattr));
 
256
                newattr.name = attr->name;
 
257
                newattr.values = g_value_array_copy(attr->values);
 
258
                /* Now append the attribute to the array. */
 
259
                g_array_append_val(dest, newattr);
 
260
        }
 
261
}
 
262
 
 
263
void
 
264
lu_ent_revert(struct lu_ent *entity)
 
265
{
 
266
        copy_attributes(entity->current, entity->pending);
 
267
}
 
268
 
 
269
void
 
270
lu_ent_commit(struct lu_ent *entity)
 
271
{
 
272
        copy_attributes(entity->pending, entity->current);
 
273
}
 
274
 
 
275
void
 
276
lu_ent_copy(struct lu_ent *source, struct lu_ent *dest)
 
277
{
 
278
        g_return_if_fail(source != NULL);
 
279
        g_return_if_fail(dest != NULL);
 
280
        g_return_if_fail(source->magic == LU_ENT_MAGIC);
 
281
        g_return_if_fail(dest->magic == LU_ENT_MAGIC);
 
282
        dest->type = source->type;
 
283
        copy_attributes(source->current, dest->current);
 
284
        copy_attributes(source->pending, dest->pending);
 
285
        g_value_array_free(dest->modules);
 
286
        dest->modules = g_value_array_copy(source->modules);
 
287
}
 
288
 
 
289
/* Return a GQark for lower-cased attribute */
 
290
static GQuark
 
291
quark_from_attribute(const char *attribute)
 
292
{
 
293
        GQuark quark;
 
294
        char *lower;
 
295
 
 
296
        lower = g_ascii_strdown(attribute, -1);
 
297
        quark = g_quark_from_string(lower);
 
298
        g_free(lower);
 
299
        return quark;
 
300
}
 
301
 
 
302
static GValueArray *
 
303
lu_ent_get_int(GArray *list, const char *attribute)
 
304
{
 
305
        struct lu_attribute *attr;
 
306
        GQuark aquark;
 
307
        size_t i;
 
308
 
 
309
        g_return_val_if_fail(list != NULL, NULL);
 
310
        g_return_val_if_fail(attribute != NULL, NULL);
 
311
        g_return_val_if_fail(strlen(attribute) > 0, NULL);
 
312
        aquark = quark_from_attribute(attribute);
 
313
        for (i = 0; i < list->len; i++) {
 
314
                attr = &g_array_index(list, struct lu_attribute, i);
 
315
                if (attr != NULL) {
 
316
                        if (attr->name == aquark) {
 
317
                                g_assert(attr->values != NULL);
 
318
                                g_assert(attr->values->n_values > 0);
 
319
                                return attr->values;
 
320
                        }
 
321
                }
 
322
        }
 
323
        return NULL;
 
324
}
 
325
 
 
326
static gboolean
 
327
lu_ent_has_int(GArray *list, const char *attribute)
 
328
{
 
329
        g_return_val_if_fail(list != NULL, FALSE);
 
330
        g_return_val_if_fail(attribute != NULL, FALSE);
 
331
        g_return_val_if_fail(strlen(attribute) > 0, FALSE);
 
332
        return (lu_ent_get_int(list, attribute) != NULL) ? TRUE : FALSE;
 
333
}
 
334
 
 
335
static void
 
336
lu_ent_clear_int(GArray *list, const char *attribute)
 
337
{
 
338
        int i;
 
339
        struct lu_attribute *attr = NULL;
 
340
        GQuark aquark;
 
341
 
 
342
        g_return_if_fail(list != NULL);
 
343
        g_return_if_fail(attribute != NULL);
 
344
        g_return_if_fail(strlen(attribute) > 0);
 
345
        aquark = quark_from_attribute(attribute);
 
346
        for (i = list->len - 1; i >= 0; i--) {
 
347
                attr = &g_array_index(list, struct lu_attribute, i);
 
348
                if (attr->name == aquark)
 
349
                        break;
 
350
        }
 
351
        if (i >= 0) {
 
352
                g_value_array_free(attr->values);
 
353
                attr->values = NULL;
 
354
                g_array_remove_index(list, i);
 
355
        }
 
356
}
 
357
 
 
358
static void
 
359
lu_ent_set_int(GArray *list, const char *attr, const GValueArray *values)
 
360
{
 
361
        GValueArray *dest, *copy;
 
362
        struct lu_attribute newattr;
 
363
        size_t i;
 
364
 
 
365
        g_return_if_fail(list != NULL);
 
366
        g_return_if_fail(attr != NULL);
 
367
        g_return_if_fail(strlen(attr) > 0);
 
368
        if (values->n_values == 0) {
 
369
                lu_ent_clear_int(list, attr);
 
370
                return;
 
371
        }
 
372
        dest = lu_ent_get_int(list, attr);
 
373
        if (dest == NULL) {
 
374
                memset(&newattr, 0, sizeof(newattr));
 
375
                newattr.name = quark_from_attribute(attr);
 
376
                newattr.values = g_value_array_new(0);
 
377
                dest = newattr.values;
 
378
                g_array_append_val(list, newattr);
 
379
        }
 
380
        while (dest->n_values > 0)
 
381
                g_value_array_remove(dest, dest->n_values - 1);
 
382
        copy = g_value_array_copy(values);
 
383
        for (i = 0; i < copy->n_values; i++)
 
384
                g_value_array_append(dest, g_value_array_get_nth(copy, i));
 
385
        g_value_array_free(copy);
 
386
}
 
387
 
 
388
static void
 
389
lu_ent_add_int(GArray *list, const char *attr, const GValue *value)
 
390
{
 
391
        GValueArray *dest;
 
392
        GValue *current;
 
393
        struct lu_attribute newattr;
 
394
        size_t i;
 
395
 
 
396
        g_return_if_fail(list != NULL);
 
397
        g_return_if_fail(value != NULL);
 
398
        g_return_if_fail(attr != NULL);
 
399
        g_return_if_fail(strlen(attr) > 0);
 
400
        dest = lu_ent_get_int(list, attr);
 
401
        if (dest == NULL) {
 
402
                memset(&newattr, 0, sizeof(newattr));
 
403
                newattr.name = quark_from_attribute(attr);
 
404
                newattr.values = g_value_array_new(1);
 
405
                dest = newattr.values;
 
406
                g_array_append_val(list, newattr);
 
407
        }
 
408
        for (i = 0; i < dest->n_values; i++) {
 
409
                current = g_value_array_get_nth(dest, i);
 
410
                if (G_VALUE_TYPE(value) == G_VALUE_TYPE(current)
 
411
                    && lu_values_equal(value, current))
 
412
                        break;
 
413
        }
 
414
        if (i >= dest->n_values)
 
415
                g_value_array_append(dest, value);
 
416
}
 
417
 
 
418
static void
 
419
lu_ent_clear_all_int(GArray *list)
 
420
{
 
421
        clear_attribute_list(list);
 
422
}
 
423
 
 
424
static void
 
425
lu_ent_del_int(GArray *list, const char *attr, const GValue *value)
 
426
{
 
427
        GValueArray *dest;
 
428
        GValue *tvalue;
 
429
        char *svalue, *tmp;
 
430
        size_t i;
 
431
        g_return_if_fail(list != NULL);
 
432
        g_return_if_fail(value != NULL);
 
433
        g_return_if_fail(attr != NULL);
 
434
        g_return_if_fail(strlen(attr) > 0);
 
435
        dest = lu_ent_get_int(list, attr);
 
436
        if (dest != NULL) {
 
437
                svalue = g_strdup_value_contents(value);
 
438
                for (i = 0; i < dest->n_values; i++) {
 
439
                        tvalue = g_value_array_get_nth(dest, i);
 
440
                        tmp = g_strdup_value_contents(tvalue);
 
441
                        if (strcmp(tmp, svalue) == 0) {
 
442
                                g_free(tmp);
 
443
                                break;
 
444
                        }
 
445
                        g_free(tmp);
 
446
                }
 
447
                g_free(svalue);
 
448
                if (i < dest->n_values) {
 
449
                        g_value_array_remove(dest, i);
 
450
                        if (dest->n_values == 0)
 
451
                                lu_ent_clear_int(list, attr);
 
452
                }
 
453
        }
 
454
}
 
455
 
 
456
static GList *
 
457
lu_ent_get_attributes_int(GArray *list)
 
458
{
 
459
        struct lu_attribute *attr;
 
460
        size_t i;
 
461
        GList *ret = NULL;
 
462
        g_return_val_if_fail(list != NULL, NULL);
 
463
        for (i = 0; i < list->len; i++) {
 
464
                attr = &g_array_index(list, struct lu_attribute, i);
 
465
                ret = g_list_prepend(ret, (char*)g_quark_to_string(attr->name));
 
466
        }
 
467
        return g_list_reverse(ret);
 
468
}
 
469
 
 
470
GValueArray *
 
471
lu_ent_get(struct lu_ent *ent, const char *attribute)
 
472
{
 
473
        g_return_val_if_fail(ent != NULL, NULL);
 
474
        g_return_val_if_fail(ent->magic == LU_ENT_MAGIC, NULL);
 
475
        g_return_val_if_fail(attribute != NULL, NULL);
 
476
        g_return_val_if_fail(strlen(attribute) > 0, NULL);
 
477
        return lu_ent_get_int(ent->pending, attribute);
 
478
}
 
479
 
 
480
GValueArray *
 
481
lu_ent_get_current(struct lu_ent *ent, const char *attribute)
 
482
{
 
483
        g_return_val_if_fail(ent != NULL, NULL);
 
484
        g_return_val_if_fail(ent->magic == LU_ENT_MAGIC, NULL);
 
485
        g_return_val_if_fail(attribute != NULL, NULL);
 
486
        g_return_val_if_fail(strlen(attribute) > 0, NULL);
 
487
        return lu_ent_get_int(ent->current, attribute);
 
488
}
 
489
 
 
490
gboolean
 
491
lu_ent_has(struct lu_ent *ent, const char *attribute)
 
492
{
 
493
        g_return_val_if_fail(ent != NULL, FALSE);
 
494
        g_return_val_if_fail(ent->magic == LU_ENT_MAGIC, FALSE);
 
495
        g_return_val_if_fail(attribute != NULL, FALSE);
 
496
        g_return_val_if_fail(strlen(attribute) > 0, FALSE);
 
497
        return lu_ent_has_int(ent->pending, attribute);
 
498
}
 
499
gboolean
 
500
lu_ent_has_current(struct lu_ent *ent, const char *attribute)
 
501
{
 
502
        g_return_val_if_fail(ent != NULL, FALSE);
 
503
        g_return_val_if_fail(ent->magic == LU_ENT_MAGIC, FALSE);
 
504
        g_return_val_if_fail(attribute != NULL, FALSE);
 
505
        g_return_val_if_fail(strlen(attribute) > 0, FALSE);
 
506
        return lu_ent_has_int(ent->current, attribute);
 
507
}
 
508
 
 
509
void
 
510
lu_ent_set(struct lu_ent *ent, const char *attribute, const GValueArray *values)
 
511
{
 
512
        g_return_if_fail(ent != NULL);
 
513
        g_return_if_fail(ent->magic == LU_ENT_MAGIC);
 
514
        g_return_if_fail(attribute != NULL);
 
515
        g_return_if_fail(strlen(attribute) > 0);
 
516
        lu_ent_set_int(ent->pending, attribute, values);
 
517
}
 
518
void
 
519
lu_ent_set_current(struct lu_ent *ent, const char *attribute,
 
520
                   const GValueArray *values)
 
521
{
 
522
        g_return_if_fail(ent != NULL);
 
523
        g_return_if_fail(ent->magic == LU_ENT_MAGIC);
 
524
        g_return_if_fail(attribute != NULL);
 
525
        g_return_if_fail(strlen(attribute) > 0);
 
526
        lu_ent_set_int(ent->current, attribute, values);
 
527
}
 
528
 
 
529
void
 
530
lu_ent_add(struct lu_ent *ent, const char *attribute, const GValue *value)
 
531
{
 
532
        g_return_if_fail(ent != NULL);
 
533
        g_return_if_fail(ent->magic == LU_ENT_MAGIC);
 
534
        g_return_if_fail(attribute != NULL);
 
535
        g_return_if_fail(strlen(attribute) > 0);
 
536
        lu_ent_add_int(ent->pending, attribute, value);
 
537
}
 
538
void
 
539
lu_ent_add_current(struct lu_ent *ent, const char *attribute,
 
540
                   const GValue *value)
 
541
{
 
542
        g_return_if_fail(ent != NULL);
 
543
        g_return_if_fail(ent->magic == LU_ENT_MAGIC);
 
544
        g_return_if_fail(attribute != NULL);
 
545
        g_return_if_fail(strlen(attribute) > 0);
 
546
        lu_ent_add_int(ent->current, attribute, value);
 
547
}
 
548
 
 
549
void
 
550
lu_ent_clear(struct lu_ent *ent, const char *attribute)
 
551
{
 
552
        g_return_if_fail(ent != NULL);
 
553
        g_return_if_fail(ent->magic == LU_ENT_MAGIC);
 
554
        g_return_if_fail(attribute != NULL);
 
555
        g_return_if_fail(strlen(attribute) > 0);
 
556
        lu_ent_clear_int(ent->pending, attribute);
 
557
}
 
558
void
 
559
lu_ent_clear_current(struct lu_ent *ent, const char *attribute)
 
560
{
 
561
        g_return_if_fail(ent != NULL);
 
562
        g_return_if_fail(ent->magic == LU_ENT_MAGIC);
 
563
        g_return_if_fail(attribute != NULL);
 
564
        g_return_if_fail(strlen(attribute) > 0);
 
565
        lu_ent_clear_int(ent->current, attribute);
 
566
}
 
567
 
 
568
void
 
569
lu_ent_clear_all(struct lu_ent *ent)
 
570
{
 
571
        g_return_if_fail(ent != NULL);
 
572
        g_return_if_fail(ent->magic == LU_ENT_MAGIC);
 
573
        lu_ent_clear_all_int(ent->pending);
 
574
}
 
575
void
 
576
lu_ent_clear_all_current(struct lu_ent *ent)
 
577
{
 
578
        g_return_if_fail(ent != NULL);
 
579
        g_return_if_fail(ent->magic == LU_ENT_MAGIC);
 
580
        lu_ent_clear_all_int(ent->current);
 
581
}
 
582
 
 
583
void
 
584
lu_ent_del(struct lu_ent *ent, const char *attribute, const GValue *value)
 
585
{
 
586
        g_return_if_fail(ent != NULL);
 
587
        g_return_if_fail(ent->magic == LU_ENT_MAGIC);
 
588
        g_return_if_fail(attribute != NULL);
 
589
        g_return_if_fail(strlen(attribute) > 0);
 
590
        g_return_if_fail(value != NULL);
 
591
        lu_ent_del_int(ent->pending, attribute, value);
 
592
}
 
593
void
 
594
lu_ent_del_current(struct lu_ent *ent, const char *attribute,
 
595
                   const GValue *value)
 
596
{
 
597
        g_return_if_fail(ent != NULL);
 
598
        g_return_if_fail(ent->magic == LU_ENT_MAGIC);
 
599
        g_return_if_fail(attribute != NULL);
 
600
        g_return_if_fail(strlen(attribute) > 0);
 
601
        g_return_if_fail(value != NULL);
 
602
        lu_ent_del_int(ent->current, attribute, value);
 
603
}
 
604
 
 
605
GList *
 
606
lu_ent_get_attributes(struct lu_ent *ent)
 
607
{
 
608
        g_return_val_if_fail(ent != NULL, NULL);
 
609
        g_return_val_if_fail(ent->magic == LU_ENT_MAGIC, NULL);
 
610
        return lu_ent_get_attributes_int(ent->pending);
 
611
}
 
612
 
 
613
GList *
 
614
lu_ent_get_attributes_current(struct lu_ent *ent)
 
615
{
 
616
        g_return_val_if_fail(ent != NULL, NULL);
 
617
        g_return_val_if_fail(ent->magic == LU_ENT_MAGIC, NULL);
 
618
        return lu_ent_get_attributes_int(ent->current);
 
619
}