10969
|
1
|
|
2 /*
|
|
3 Meanwhile - Unofficial Lotus Sametime Community Client Library
|
|
4 Copyright (C) 2004 Christopher (siege) O'Brien
|
|
5
|
|
6 This library is free software; you can redistribute it and/or
|
|
7 modify it under the terms of the GNU Library General Public
|
|
8 License as published by the Free Software Foundation; either
|
|
9 version 2 of the License, or (at your option) any later version.
|
|
10
|
|
11 This library is distributed in the hope that it will be useful,
|
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
14 Library General Public License for more details.
|
|
15
|
|
16 You should have received a copy of the GNU Library General Public
|
|
17 License along with this library; if not, write to the Free
|
|
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
19 */
|
|
20
|
|
21 #include "mw_util.h"
|
|
22
|
|
23
|
|
24 static void collect_keys(gpointer key, gpointer val, gpointer data) {
|
|
25 GList **list = data;
|
|
26 *list = g_list_append(*list, key);
|
|
27 }
|
|
28
|
|
29
|
|
30 GList *map_collect_keys(GHashTable *ht) {
|
|
31 GList *ret = NULL;
|
|
32 g_hash_table_foreach(ht, collect_keys, &ret);
|
|
33 return ret;
|
|
34 }
|
|
35
|
|
36
|
|
37 static void collect_values(gpointer key, gpointer val, gpointer data) {
|
|
38 GList **list = data;
|
|
39 *list = g_list_append(*list, val);
|
|
40 }
|
|
41
|
|
42
|
|
43 GList *map_collect_values(GHashTable *ht) {
|
|
44 GList *ret = NULL;
|
|
45 g_hash_table_foreach(ht, collect_values, &ret);
|
|
46 return ret;
|
|
47 }
|
|
48
|
|
49
|
|
50 struct mw_datum *mw_datum_new(gpointer data, GDestroyNotify clear) {
|
|
51 struct mw_datum *d = g_new(struct mw_datum, 1);
|
|
52 mw_datum_set(d, data, clear);
|
|
53 return d;
|
|
54 }
|
|
55
|
|
56
|
|
57 void mw_datum_set(struct mw_datum *d, gpointer data, GDestroyNotify clear) {
|
|
58 d->data = data;
|
|
59 d->clear = clear;
|
|
60 }
|
|
61
|
|
62
|
|
63 gpointer mw_datum_get(struct mw_datum *d) {
|
|
64 return d->data;
|
|
65 }
|
|
66
|
|
67
|
|
68 void mw_datum_clear(struct mw_datum *d) {
|
|
69 if(d->clear) {
|
|
70 d->clear(d->data);
|
|
71 d->clear = NULL;
|
|
72 }
|
|
73 d->data = NULL;
|
|
74 }
|
|
75
|
|
76
|
|
77 void mw_datum_free(struct mw_datum *d) {
|
|
78 mw_datum_clear(d);
|
|
79 g_free(d);
|
|
80 }
|
12166
|
81
|
|
82 gboolean
|
|
83 mw_str_has_prefix(const char *s, const char *p)
|
|
84 {
|
|
85 #if GLIB_CHECK_VERSION(2,2,0)
|
|
86 return g_str_has_prefix(s, p);
|
|
87 #else
|
|
88 if (!strncmp(s, p, strlen(p)))
|
|
89 return TRUE;
|
|
90
|
|
91 return FALSE;
|
|
92 #endif
|
|
93 }
|
|
94
|