~ubuntu-branches/ubuntu/wily/libuser/wily

« back to all changes in this revision

Viewing changes to lib/entity.c

  • Committer: Bazaar Package Importer
  • Author(s): Pierre Habouzit
  • Date: 2006-09-03 21:58:15 UTC
  • mto: (2.1.1 edgy) (1.1.5 upstream) (3.1.1 lenny)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20060903215815-rtvvfzhaer8ymyp4
Tags: upstream-0.54.6-2.1.dfsg.1
ImportĀ upstreamĀ versionĀ 0.54.6-2.1.dfsg.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
17
 */
18
18
 
19
 
#ident "$Id: entity.c,v 1.30 2005/09/12 23:24:37 mitr Exp $"
 
19
#ident "$Id: entity.c,v 1.31 2005/10/09 05:15:47 mitr Exp $"
20
20
 
21
21
#ifdef HAVE_CONFIG_H
22
22
#include "../config.h"
34
34
struct lu_ent *
35
35
lu_ent_new()
36
36
{
37
 
        struct lu_ent *ent = NULL;
 
37
        struct lu_ent *ent;
 
38
 
38
39
        ent = g_malloc0(sizeof(struct lu_ent));
39
40
        ent->magic = LU_ENT_MAGIC;
40
41
        ent->cache = lu_string_cache_new(TRUE);
184
185
void
185
186
lu_ent_add_module(struct lu_ent *ent, const char *source)
186
187
{
187
 
        GValue value, *val;
 
188
        GValue value;
188
189
        size_t i;
189
190
        g_return_if_fail(ent != NULL);
190
191
        g_return_if_fail(ent->magic == LU_ENT_MAGIC);
195
196
        g_value_set_string(&value, source);
196
197
        /* Now scan the array for the value. */
197
198
        for (i = 0; i < ent->modules->n_values; i++) {
 
199
                GValue *val;
 
200
 
198
201
                val = g_value_array_get_nth(ent->modules, i);
199
202
                /* We only add strings, so there had better be only strings
200
203
                 * in this list, otherwise someone is messing with us. */
229
232
clear_attribute_list(GArray *dest)
230
233
{
231
234
        int i;
232
 
        struct lu_attribute *attr;
 
235
 
233
236
        for (i = dest->len - 1; i >= 0; i--) {
 
237
                struct lu_attribute *attr;
 
238
 
234
239
                attr = &g_array_index(dest, struct lu_attribute, i);
235
240
                g_value_array_free(attr->values);
236
241
                attr->values = NULL;
244
249
copy_attributes(GArray *source, GArray *dest)
245
250
{
246
251
        size_t i;
247
 
        struct lu_attribute *attr, newattr;
 
252
 
248
253
        /* First, clear the destination list of all attributes. */
249
254
        clear_attribute_list(dest);
250
255
        /* Now copy all of the attributes and their values. */
251
256
        for (i = 0; i < source->len; i++) {
 
257
                struct lu_attribute *attr, newattr;
 
258
 
252
259
                attr = &g_array_index(source, struct lu_attribute, i);
253
260
                /* Copy the attribute name, then its values, into the holding
254
261
                 * area. */
302
309
static GValueArray *
303
310
lu_ent_get_int(GArray *list, const char *attribute)
304
311
{
305
 
        struct lu_attribute *attr;
306
312
        GQuark aquark;
307
313
        size_t i;
308
314
 
311
317
        g_return_val_if_fail(strlen(attribute) > 0, NULL);
312
318
        aquark = quark_from_attribute(attribute);
313
319
        for (i = 0; i < list->len; i++) {
 
320
                struct lu_attribute *attr;
 
321
 
314
322
                attr = &g_array_index(list, struct lu_attribute, i);
315
323
                if (attr != NULL) {
316
324
                        if (attr->name == aquark) {
359
367
lu_ent_set_int(GArray *list, const char *attr, const GValueArray *values)
360
368
{
361
369
        GValueArray *dest, *copy;
362
 
        struct lu_attribute newattr;
363
370
        size_t i;
364
371
 
365
372
        g_return_if_fail(list != NULL);
371
378
        }
372
379
        dest = lu_ent_get_int(list, attr);
373
380
        if (dest == NULL) {
 
381
                struct lu_attribute newattr;
 
382
 
374
383
                memset(&newattr, 0, sizeof(newattr));
375
384
                newattr.name = quark_from_attribute(attr);
376
385
                newattr.values = g_value_array_new(0);
389
398
lu_ent_add_int(GArray *list, const char *attr, const GValue *value)
390
399
{
391
400
        GValueArray *dest;
392
 
        GValue *current;
393
 
        struct lu_attribute newattr;
394
401
        size_t i;
395
402
 
396
403
        g_return_if_fail(list != NULL);
399
406
        g_return_if_fail(strlen(attr) > 0);
400
407
        dest = lu_ent_get_int(list, attr);
401
408
        if (dest == NULL) {
 
409
                struct lu_attribute newattr;
 
410
 
402
411
                memset(&newattr, 0, sizeof(newattr));
403
412
                newattr.name = quark_from_attribute(attr);
404
413
                newattr.values = g_value_array_new(1);
406
415
                g_array_append_val(list, newattr);
407
416
        }
408
417
        for (i = 0; i < dest->n_values; i++) {
 
418
                GValue *current;
 
419
 
409
420
                current = g_value_array_get_nth(dest, i);
410
421
                if (G_VALUE_TYPE(value) == G_VALUE_TYPE(current)
411
422
                    && lu_values_equal(value, current))
425
436
lu_ent_del_int(GArray *list, const char *attr, const GValue *value)
426
437
{
427
438
        GValueArray *dest;
428
 
        GValue *tvalue;
429
 
        char *svalue, *tmp;
430
439
        size_t i;
431
440
        g_return_if_fail(list != NULL);
432
441
        g_return_if_fail(value != NULL);
434
443
        g_return_if_fail(strlen(attr) > 0);
435
444
        dest = lu_ent_get_int(list, attr);
436
445
        if (dest != NULL) {
 
446
                char *svalue;
 
447
 
437
448
                svalue = g_strdup_value_contents(value);
438
449
                for (i = 0; i < dest->n_values; i++) {
 
450
                        GValue *tvalue;
 
451
                        char *tmp;
 
452
 
439
453
                        tvalue = g_value_array_get_nth(dest, i);
440
454
                        tmp = g_strdup_value_contents(tvalue);
441
455
                        if (strcmp(tmp, svalue) == 0) {
456
470
static GList *
457
471
lu_ent_get_attributes_int(GArray *list)
458
472
{
459
 
        struct lu_attribute *attr;
460
473
        size_t i;
461
474
        GList *ret = NULL;
462
475
        g_return_val_if_fail(list != NULL, NULL);
463
476
        for (i = 0; i < list->len; i++) {
 
477
                struct lu_attribute *attr;
 
478
 
464
479
                attr = &g_array_index(list, struct lu_attribute, i);
465
480
                ret = g_list_prepend(ret, (char*)g_quark_to_string(attr->name));
466
481
        }