annotate src/audacious/tuple.c @ 3494:7d1dee4f660a trunk

Check for known fields in tuple_associate_data() when given nfield is undefined.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 05 Sep 2007 03:28:30 +0300
parents 899a7ed37a70
children 6f34cc4217b9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
1 /*
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
2 * Audacious
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
3 * Copyright (c) 2006-2007 Audacious team
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
4 *
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
6 * it under the terms of the GNU General Public License as published by
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
7 * the Free Software Foundation; under version 3 of the License.
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
8 *
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful,
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
12 * GNU General Public License for more details.
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
13 *
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
15 * along with this program. If not, see <http://www.gnu.org/licenses>.
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
16 *
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
17 * The Audacious team does not consider modular code linking to
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
18 * Audacious or using our public API to be a derived work.
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
19 */
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
20
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
21 #include <glib.h>
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
22 #include <mowgli.h>
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
23
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
24 #include "tuple.h"
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
25
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
26
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
27 const gchar *tuple_fields[FIELD_LAST] = {
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
28 "artist",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
29 "title",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
30 "album",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
31 "comment",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
32 "genre",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
33
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
34 "track",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
35 "track-number",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
36 "length",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
37 "year",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
38 "quality",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
39
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
40 "codec",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
41 "file-name",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
42 "file-path",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
43 "file-ext",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
44 "song-artist",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
45
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
46 "mtime",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
47 "formatter",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
48 "performer",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
49 "copyright",
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
50 };
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
51
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
52
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
53 static mowgli_heap_t *tuple_heap = NULL;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
54 static mowgli_heap_t *tuple_value_heap = NULL;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
55 static mowgli_object_class_t tuple_klass;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
56
3280
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
57 /* iterative destructor of tuple values. */
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
58 static void
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
59 tuple_value_destroy(mowgli_dictionary_elem_t *delem, gpointer privdata)
3280
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
60 {
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
61 TupleValue *value = (TupleValue *) delem->data;
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
62
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
63 if (value->type == TUPLE_STRING)
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
64 g_free(value->value.string);
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
65
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
66 mowgli_heap_free(tuple_value_heap, value);
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
67 }
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
68
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
69 static void
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
70 tuple_destroy(gpointer data)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
71 {
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
72 Tuple *tuple = (Tuple *) data;
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
73
3280
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
74 mowgli_dictionary_destroy(tuple->dict, tuple_value_destroy, NULL);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
75 mowgli_heap_free(tuple_heap, tuple);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
76 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
77
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
78 Tuple *
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
79 tuple_new(void)
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
80 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
81 Tuple *tuple;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
82
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
83 if (tuple_heap == NULL)
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
84 {
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
85 tuple_heap = mowgli_heap_create(sizeof(Tuple), 32, BH_NOW);
3281
be80d9b2c9ef Error fixes.
William Pitcock <nenolod@atheme-project.org>
parents: 3280
diff changeset
86 tuple_value_heap = mowgli_heap_create(sizeof(TupleValue), 512, BH_NOW);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
87 mowgli_object_class_init(&tuple_klass, "audacious.tuple", tuple_destroy, FALSE);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
88 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
89
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
90 /* FIXME: use mowgli_object_bless_from_class() in mowgli 0.4
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
91 when it is released --nenolod */
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
92 tuple = mowgli_heap_alloc(tuple_heap);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
93 mowgli_object_init(mowgli_object(tuple), NULL, &tuple_klass, NULL);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
94
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
95 tuple->dict = mowgli_dictionary_create(g_ascii_strcasecmp);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
96
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
97 return tuple;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
98 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
99
3301
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
100 Tuple *
3304
00286cde2485 Make filename a const
Christian Birchinger <joker@netswarm.net>
parents: 3303
diff changeset
101 tuple_new_from_filename(const gchar *filename)
3301
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
102 {
3303
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
103 gchar *scratch, *ext, *realfn;
3301
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
104 Tuple *tuple;
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
105
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
106 g_return_val_if_fail(filename != NULL, NULL);
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
107
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
108 tuple = tuple_new();
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
109
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
110 g_return_val_if_fail(tuple != NULL, NULL);
3303
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
111
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
112 realfn = g_filename_from_uri(filename, NULL, NULL);
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
113
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
114 scratch = g_path_get_basename(realfn ? realfn : filename);
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
115 tuple_associate_string(tuple, FIELD_FILE_NAME, NULL, scratch);
3301
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
116 g_free(scratch);
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
117
3303
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
118 scratch = g_path_get_dirname(realfn ? realfn : filename);
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
119 tuple_associate_string(tuple, FIELD_FILE_PATH, NULL, scratch);
3301
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
120 g_free(scratch);
3303
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
121
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
122 g_free(realfn); realfn = NULL;
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
123
3301
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
124 ext = strrchr(filename, '.');
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
125 if (ext != NULL) {
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
126 ++ext;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
127 tuple_associate_string(tuple, FIELD_FILE_EXT, NULL, scratch);
3301
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
128 }
3303
eaf68ed98166 Use real filenames inside tuples not URIs
Christian Birchinger <joker@netswarm.net>
parents: 3301
diff changeset
129
3301
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
130 return tuple;
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
131 }
008530664ba1 Add tuple_new_from_filename() which creates a new tuple with file-name, file-path and file-ext.
Christian Birchinger <joker@netswarm.net>
parents: 3282
diff changeset
132
3491
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
133
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
134 static gboolean
3494
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
135 tuple_associate_data(const gchar **tfield, TupleValue **value, Tuple *tuple, gint *nfield, const gchar *field)
3491
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
136 {
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
137 g_return_val_if_fail(tuple != NULL, FALSE);
3494
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
138 g_return_val_if_fail(*nfield < FIELD_LAST, FALSE);
3491
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
139
3494
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
140 /* Check for known fields */
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
141 if (*nfield < 0) {
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
142 gint i;
3491
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
143 *tfield = field;
3494
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
144 for (i = 0; i < FIELD_LAST && *nfield < 0; i++)
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
145 if (!strcmp(field, tuple_fields[i])) *nfield = i;
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
146 }
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
147
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
148 if (*nfield >= 0) {
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
149 *tfield = tuple_fields[*nfield];
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
150 tuple->values[*nfield] = NULL;
3491
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
151 }
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
152
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
153 if ((*value = mowgli_dictionary_delete(tuple->dict, *tfield)))
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
154 tuple_disassociate_now(*value);
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
155
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
156 return TRUE;
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
157 }
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
158
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
159 static void
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
160 tuple_associate_data2(Tuple *tuple, const gint nfield, const gchar *field, TupleValue *value)
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
161 {
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
162 mowgli_dictionary_add(tuple->dict, field, value);
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
163
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
164 if (nfield >= 0)
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
165 tuple->values[nfield] = value;
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
166 }
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
167
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
168 gboolean
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
169 tuple_associate_string(Tuple *tuple, const gint nfield, const gchar *field, const gchar *string)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
170 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
171 TupleValue *value;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
172 const gchar *tfield;
3494
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
173 gint ifield = nfield;
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
174
3494
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
175 if (!tuple_associate_data(&tfield, &value, tuple, &ifield, field))
3491
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
176 return FALSE;
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
177
3329
70149c3555f4 For interest of transparency, make associating NULL equivilant to deleting the field.
William Pitcock <nenolod@atheme-project.org>
parents: 3304
diff changeset
178 if (string == NULL)
70149c3555f4 For interest of transparency, make associating NULL equivilant to deleting the field.
William Pitcock <nenolod@atheme-project.org>
parents: 3304
diff changeset
179 return TRUE;
70149c3555f4 For interest of transparency, make associating NULL equivilant to deleting the field.
William Pitcock <nenolod@atheme-project.org>
parents: 3304
diff changeset
180
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
181 value = mowgli_heap_alloc(tuple_value_heap);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
182 value->type = TUPLE_STRING;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
183 value->value.string = g_strdup(string);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
184
3494
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
185 tuple_associate_data2(tuple, ifield, tfield, value);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
186 return TRUE;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
187 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
188
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
189 gboolean
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
190 tuple_associate_int(Tuple *tuple, const gint nfield, const gchar *field, gint integer)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
191 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
192 TupleValue *value;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
193 const gchar *tfield;
3494
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
194 gint ifield = nfield;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
195
3494
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
196 if (!tuple_associate_data(&tfield, &value, tuple, &ifield, field))
3491
899a7ed37a70 Clean up tiny bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents: 3489
diff changeset
197 return FALSE;
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
198
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
199 value = mowgli_heap_alloc(tuple_value_heap);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
200 value->type = TUPLE_INT;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
201 value->value.integer = integer;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
202
3494
7d1dee4f660a Check for known fields in tuple_associate_data() when given nfield is
Matti Hamalainen <ccr@tnsp.org>
parents: 3491
diff changeset
203 tuple_associate_data2(tuple, ifield, tfield, value);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
204 return TRUE;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
205 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
206
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
207 void
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents: 3329
diff changeset
208 tuple_disassociate_now(TupleValue *value)
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents: 3329
diff changeset
209 {
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents: 3329
diff changeset
210 if (value->type == TUPLE_STRING)
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents: 3329
diff changeset
211 g_free(value->value.string);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents: 3329
diff changeset
212
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents: 3329
diff changeset
213 mowgli_heap_free(tuple_value_heap, value);
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents: 3329
diff changeset
214 }
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents: 3329
diff changeset
215
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents: 3329
diff changeset
216 void
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
217 tuple_disassociate(Tuple *tuple, const gint nfield, const gchar *field)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
218 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
219 TupleValue *value;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
220 const gchar *tfield;
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
221
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
222 g_return_if_fail(tuple != NULL);
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
223 g_return_if_fail(nfield < FIELD_LAST);
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
224
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
225 if (nfield < 0)
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
226 tfield = field;
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
227 else {
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
228 tfield = tuple_fields[nfield];
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
229 tuple->values[nfield] = NULL;
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
230 }
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
231
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
232 /* why _delete()? because _delete() returns the dictnode's data on success */
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
233 if ((value = mowgli_dictionary_delete(tuple->dict, tfield)) == NULL)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
234 return;
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
235
3409
86dafe2300f7 Added Tuplez compiler (not used yet, though) and some related changes in
Matti Hamalainen <ccr@tnsp.org>
parents: 3329
diff changeset
236 tuple_disassociate_now(value);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
237 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
238
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
239 TupleValueType
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
240 tuple_get_value_type(Tuple *tuple, const gint nfield, const gchar *field)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
241 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
242 TupleValue *value;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
243
3280
a26138e391ee Tuple engine cleanups.
William Pitcock <nenolod@atheme-project.org>
parents: 3278
diff changeset
244 g_return_val_if_fail(tuple != NULL, TUPLE_UNKNOWN);
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
245 g_return_val_if_fail(nfield < FIELD_LAST, TUPLE_UNKNOWN);
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
246
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
247 if (nfield < 0) {
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
248 if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) != NULL)
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
249 return value->type;
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
250 } else {
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
251 if (tuple->values[nfield])
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
252 return tuple->values[nfield]->type;
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
253 }
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
254
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
255 return TUPLE_UNKNOWN;
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
256 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
257
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
258 const gchar *
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
259 tuple_get_string(Tuple *tuple, const gint nfield, const gchar *field)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
260 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
261 TupleValue *value;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
262
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
263 g_return_val_if_fail(tuple != NULL, NULL);
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
264 g_return_val_if_fail(nfield < FIELD_LAST, NULL);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
265
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
266 if (nfield < 0) {
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
267 if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) == NULL)
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
268 return NULL;
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
269 } else {
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
270 if (tuple->values[nfield])
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
271 value = tuple->values[nfield];
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
272 else
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
273 return NULL;
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
274 }
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
275
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
276 if (value->type != TUPLE_STRING)
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
277 mowgli_throw_exception_val(audacious.tuple.invalid_type_request, NULL);
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
279 return value->value.string;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
280 }
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
281
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
282 gint
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
283 tuple_get_int(Tuple *tuple, const gint nfield, const gchar *field)
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
284 {
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
285 TupleValue *value;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
286
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
287 g_return_val_if_fail(tuple != NULL, 0);
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
288 g_return_val_if_fail(nfield < FIELD_LAST, 0);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
289
3489
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
290 if (nfield < 0) {
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
291 if ((value = mowgli_dictionary_retrieve(tuple->dict, field)) == NULL)
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
292 return 0;
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
293 } else {
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
294 if (tuple->values[nfield])
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
295 value = tuple->values[nfield];
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
296 else
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
297 return 0;
9580bb3e58fa Tuple handling API changed to include support for "hardcoded" fields.
Matti Hamalainen <ccr@tnsp.org>
parents: 3409
diff changeset
298 }
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
299
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
300 if (value->type != TUPLE_INT)
3282
b78d3197c70d Tuple (final version)
William Pitcock <nenolod@atheme-project.org>
parents: 3281
diff changeset
301 mowgli_throw_exception_val(audacious.tuple.invalid_type_request, 0);
3278
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
302
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
303 return value->value.integer;
04df6bd984ad Tuple API try 1.
William Pitcock <nenolod@atheme-project.org>
parents:
diff changeset
304 }