8810
|
1 /**
|
|
2 * @file table.c MSN helper structure
|
|
3 *
|
|
4 * gaim
|
|
5 *
|
|
6 * Copyright (C) 2003, Christian Hammond <chipx86@gnupdate.org>
|
|
7 *
|
|
8 * This program is free software; you can redistribute it and/or modify
|
|
9 * it under the terms of the GNU General Public License as published by
|
|
10 * the Free Software Foundation; either version 2 of the License, or
|
|
11 * (at your option) any later version.
|
|
12 *
|
|
13 * This program is distributed in the hope that it will be useful,
|
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16 * GNU General Public License for more details.
|
|
17 *
|
|
18 * You should have received a copy of the GNU General Public License
|
|
19 * along with this program; if not, write to the Free Software
|
|
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
21 */
|
|
22 #include "msn.h"
|
|
23 #include "table.h"
|
|
24
|
|
25 static void
|
|
26 null_cmd_cb(MsnCmdProc *cmdproc, MsnCommand *cmd)
|
|
27 {
|
|
28 }
|
|
29
|
|
30 static void
|
|
31 null_error_cb(MsnCmdProc *cmdproc, MsnTransaction *trans, int error)
|
|
32 {
|
|
33 }
|
|
34
|
|
35 MsnTable *
|
|
36 msn_table_new()
|
|
37 {
|
|
38 MsnTable *table;
|
|
39
|
|
40 table = g_new0(MsnTable, 1);
|
|
41
|
|
42 table->cmds = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
|
|
43 table->msgs = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
|
|
44 table->errors = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
|
|
45
|
|
46 table->async = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
|
|
47
|
|
48 return table;
|
|
49 }
|
|
50
|
|
51 void
|
|
52 msn_table_destroy(MsnTable *table)
|
|
53 {
|
|
54 g_return_if_fail(table != NULL);
|
|
55
|
|
56 g_hash_table_destroy(table->cmds);
|
|
57 g_hash_table_destroy(table->msgs);
|
|
58 g_hash_table_destroy(table->errors);
|
|
59
|
|
60 g_hash_table_destroy(table->async);
|
|
61
|
|
62 g_free(table);
|
|
63 }
|
|
64
|
|
65 void
|
|
66 msn_table_add_cmd(MsnTable *table,
|
|
67 char *command, char *answer, MsnTransCb cb)
|
|
68 {
|
|
69 GHashTable *cbs;
|
|
70
|
|
71 g_return_if_fail(table != NULL);
|
|
72 g_return_if_fail(answer != NULL);
|
|
73
|
|
74 cbs = NULL;
|
|
75
|
|
76 if (command == NULL)
|
|
77 {
|
|
78 cbs = table->async;
|
|
79 }
|
|
80 else
|
|
81 {
|
|
82 cbs = g_hash_table_lookup(table->cmds, command);
|
|
83
|
|
84 if (cbs == NULL)
|
|
85 {
|
|
86 cbs = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL);
|
|
87 g_hash_table_insert(table->cmds, command, cbs);
|
|
88 }
|
|
89 }
|
|
90
|
|
91 if (cb == NULL)
|
|
92 cb = null_cmd_cb;
|
|
93
|
|
94 g_hash_table_insert(cbs, answer, cb);
|
|
95 }
|
|
96
|
|
97 void
|
|
98 msn_table_add_error(MsnTable *table,
|
|
99 char *answer, MsnErrorCb cb)
|
|
100 {
|
|
101 g_return_if_fail(table != NULL);
|
|
102 g_return_if_fail(answer != NULL);
|
|
103
|
|
104 if (cb == NULL)
|
|
105 cb = null_error_cb;
|
|
106
|
|
107 g_hash_table_insert(table->errors, answer, cb);
|
|
108 }
|
|
109
|
|
110 void
|
|
111 msn_table_add_msg_type(MsnTable *table,
|
|
112 char *type, MsnMsgCb cb)
|
|
113 {
|
|
114 g_return_if_fail(table != NULL);
|
|
115 g_return_if_fail(type != NULL);
|
|
116 g_return_if_fail(cb != NULL);
|
|
117
|
|
118 #if 0
|
|
119 if (cb == NULL)
|
|
120 cb = null_msg_cb;
|
|
121 #endif
|
|
122
|
|
123 g_hash_table_insert(table->msgs, type, cb);
|
|
124 }
|