Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
e2dc3c94
Commit
e2dc3c94
authored
Mar 11, 2009
by
Eric Wollesen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move from the opaque GPtrArray to GHashTable for sticker lists.
parent
ce6ef89f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
34 additions
and
45 deletions
+34
-45
command.c
src/command.c
+13
-20
song_sticker.c
src/song_sticker.c
+4
-4
song_sticker.h
src/song_sticker.h
+3
-5
sticker.c
src/sticker.c
+10
-11
sticker.h
src/sticker.h
+4
-5
No files found.
src/command.c
View file @
e2dc3c94
...
...
@@ -1448,6 +1448,13 @@ handle_idle(struct client *client,
}
#ifdef ENABLE_SQLITE
static
void
print_sticker
(
GString
*
name
,
GString
*
value
,
struct
client
*
client
)
{
client_printf
(
client
,
"sticker: %s=%s
\n
"
,
(
char
*
)
name
,
(
char
*
)
value
);
}
static
enum
command_return
handle_sticker_song
(
struct
client
*
client
,
int
argc
,
char
*
argv
[])
{
...
...
@@ -1474,31 +1481,17 @@ handle_sticker_song(struct client *client, int argc, char *argv[])
return
COMMAND_RETURN_OK
;
}
else
if
(
argc
==
4
&&
strcmp
(
argv
[
1
],
"list"
)
==
0
)
{
GList
*
list
;
GPtrArray
*
values
;
unsigned
int
x
;
GHashTable
*
hash
;
list
=
sticker_song_list_values
(
song
);
if
(
NULL
==
list
)
{
hash
=
sticker_song_list_values
(
song
);
if
(
NULL
==
hash
)
{
command_error
(
client
,
ACK_ERROR_NO_EXIST
,
"no stickers found"
);
return
COMMAND_RETURN_ERROR
;
}
for
(
x
=
0
;
x
<
g_list_length
(
list
);
x
++
)
{
values
=
g_list_nth_data
(
list
,
x
);
if
(
NULL
==
values
)
{
g_warning
(
"NULL sticker found"
);
continue
;
}
client_printf
(
client
,
"sticker: %s=%s
\n
"
,
(
char
*
)
g_ptr_array_index
(
values
,
0
),
(
char
*
)
g_ptr_array_index
(
values
,
1
));
g_free
(
g_ptr_array_index
(
values
,
0
));
g_free
(
g_ptr_array_index
(
values
,
1
));
g_ptr_array_free
(
values
,
TRUE
);
}
g_list_free
(
list
);
g_hash_table_foreach
(
hash
,
(
GHFunc
)
print_sticker
,
client
);
g_hash_table_destroy
(
hash
);
return
COMMAND_RETURN_OK
;
}
else
if
(
argc
==
6
&&
strcmp
(
argv
[
1
],
"set"
)
==
0
)
{
...
...
src/song_sticker.c
View file @
e2dc3c94
...
...
@@ -39,20 +39,20 @@ sticker_song_get_value(const struct song *song, const char *name)
return
value
;
}
G
List
*
G
HashTable
*
sticker_song_list_values
(
const
struct
song
*
song
)
{
char
*
uri
;
G
List
*
list
;
G
HashTable
*
hash
;
assert
(
song
!=
NULL
);
assert
(
song_in_database
(
song
));
uri
=
song_get_uri
(
song
);
list
=
sticker_list_values
(
"song"
,
uri
);
hash
=
sticker_list_values
(
"song"
,
uri
);
g_free
(
uri
);
return
list
;
return
hash
;
}
bool
...
...
src/song_sticker.h
View file @
e2dc3c94
...
...
@@ -40,12 +40,10 @@ sticker_song_set_value(const struct song *song,
const
char
*
name
,
const
char
*
value
);
/**
* Returns a list of key value pairs from a song's sticker record.
* The caller must free each GPtrArray element of the returned list
* with g_ptr_array_free(), as well as the returned GList with
* g_list_free().
* Returns a hash table of key value pairs from a song's sticker record.
* The caller must free the GHashTable with g_hash_table_destroy().
*/
G
List
*
G
HashTable
*
sticker_song_list_values
(
const
struct
song
*
song
);
/**
...
...
src/sticker.c
View file @
e2dc3c94
...
...
@@ -189,15 +189,14 @@ sticker_load_value(const char *type, const char *uri, const char *name)
return
value
;
}
G
List
*
G
HashTable
*
sticker_list_values
(
const
char
*
type
,
const
char
*
uri
)
{
int
ret
;
char
*
name
,
*
value
;
GPtrArray
*
arr
;
GList
*
list
;
GHashTable
*
hash
;
list
=
NULL
;
hash
=
NULL
;
assert
(
type
!=
NULL
);
assert
(
uri
!=
NULL
);
...
...
@@ -223,12 +222,14 @@ sticker_list_values(const char *type, const char *uri)
ret
=
sqlite3_step
(
sticker_stmt_list
);
switch
(
ret
)
{
case
SQLITE_ROW
:
if
(
!
hash
)
hash
=
g_hash_table_new_full
(
g_str_hash
,
g_str_equal
,
(
GDestroyNotify
)
g_free
,
(
GDestroyNotify
)
g_free
);
name
=
g_strdup
((
const
char
*
)
sqlite3_column_text
(
sticker_stmt_list
,
0
));
value
=
g_strdup
((
const
char
*
)
sqlite3_column_text
(
sticker_stmt_list
,
1
));
arr
=
g_ptr_array_new
();
g_ptr_array_add
(
arr
,
name
);
g_ptr_array_add
(
arr
,
value
);
list
=
g_list_prepend
(
list
,
arr
);
g_hash_table_insert
(
hash
,
name
,
value
);
break
;
case
SQLITE_DONE
:
break
;
...
...
@@ -242,12 +243,10 @@ sticker_list_values(const char *type, const char *uri)
}
}
while
(
ret
!=
SQLITE_DONE
);
list
=
g_list_reverse
(
list
);
sqlite3_reset
(
sticker_stmt_list
);
sqlite3_clear_bindings
(
sticker_stmt_list
);
return
list
;
return
hash
;
}
static
bool
...
...
src/sticker.h
View file @
e2dc3c94
...
...
@@ -64,12 +64,11 @@ bool
sticker_enabled
(
void
);
/**
* Populates a GList with GPtrArrays of sticker names and values from
* an object's sticker record. The caller must free each GPtrArray
* element of the returned list with g_ptr_array_free(), as well as
* the returned GList with g_list_free().
* Populates a GHashTable with GStrings of sticker keys and values
* from an object's sticker record. The caller must free the returned
* GHashTable with g_hash_list_destroy().
*/
G
List
*
G
HashTable
*
sticker_list_values
(
const
char
*
type
,
const
char
*
uri
);
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment