Mercurial > pidgin
annotate libgaim/protocols/msn/table.c @ 20397:6ac7e33fdabf
propagate from branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-1-rlaager-whitespace' (head 5083cfbc09503360bacf3ff0ebf528700770e6af)
to branch 'im.pidgin.rlaager.merging.msnp13-and-sf-1621854-4-rlaager-whitespace' (head 4d82c29e56bd33cd6f94302e343dfeb5d68ab3eb)
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Sun, 15 Apr 2007 03:04:05 +0000 |
parents | e354528c4163 |
children |
rev | line source |
---|---|
14192 | 1 /** |
2 * @file table.c MSN helper structure | |
3 * | |
4 * gaim | |
5 * | |
6 * Gaim is the legal property of its developers, whose names are too numerous | |
7 * to list here. Please refer to the COPYRIGHT file distributed with this | |
8 * source distribution. | |
9 * | |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 */ | |
24 #include "msn.h" | |
25 #include "table.h" | |
26 | |
27 static void | |
28 null_cmd_cb(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
29 { | |
30 } | |
31 | |
32 static void | |
33 null_error_cb(MsnCmdProc *cmdproc, MsnTransaction *trans, int error) | |
34 { | |
35 } | |
36 | |
37 MsnTable * | |
38 msn_table_new() | |
39 { | |
40 MsnTable *table; | |
41 | |
42 table = g_new0(MsnTable, 1); | |
43 | |
44 table->cmds = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); | |
45 table->msgs = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); | |
46 table->errors = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); | |
47 | |
48 table->async = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); | |
49 table->fallback = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); | |
50 | |
51 return table; | |
52 } | |
53 | |
54 void | |
55 msn_table_destroy(MsnTable *table) | |
56 { | |
57 g_return_if_fail(table != NULL); | |
58 | |
59 g_hash_table_destroy(table->cmds); | |
60 g_hash_table_destroy(table->msgs); | |
61 g_hash_table_destroy(table->errors); | |
62 | |
63 g_hash_table_destroy(table->async); | |
64 g_hash_table_destroy(table->fallback); | |
65 | |
66 g_free(table); | |
67 } | |
68 | |
69 void | |
70 msn_table_add_cmd(MsnTable *table, | |
71 char *command, char *answer, MsnTransCb cb) | |
72 { | |
73 GHashTable *cbs; | |
74 | |
75 g_return_if_fail(table != NULL); | |
76 g_return_if_fail(answer != NULL); | |
77 | |
78 cbs = NULL; | |
79 | |
20389
e354528c4163
propagate from branch 'im.pidgin.gaim' (head 70ac931e4936c7916eec18a07fe46a0af0fd7403)
Richard Laager <rlaager@wiktel.com>
parents:
14192
diff
changeset
|
80 if (command == NULL){ |
14192 | 81 cbs = table->async; |
20389
e354528c4163
propagate from branch 'im.pidgin.gaim' (head 70ac931e4936c7916eec18a07fe46a0af0fd7403)
Richard Laager <rlaager@wiktel.com>
parents:
14192
diff
changeset
|
82 }else if (strcmp(command, "fallback") == 0) { |
14192 | 83 cbs = table->fallback; |
20389
e354528c4163
propagate from branch 'im.pidgin.gaim' (head 70ac931e4936c7916eec18a07fe46a0af0fd7403)
Richard Laager <rlaager@wiktel.com>
parents:
14192
diff
changeset
|
84 }else{ |
14192 | 85 cbs = g_hash_table_lookup(table->cmds, command); |
86 | |
20389
e354528c4163
propagate from branch 'im.pidgin.gaim' (head 70ac931e4936c7916eec18a07fe46a0af0fd7403)
Richard Laager <rlaager@wiktel.com>
parents:
14192
diff
changeset
|
87 if (cbs == NULL){ |
14192 | 88 cbs = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, NULL); |
89 g_hash_table_insert(table->cmds, command, cbs); | |
90 } | |
91 } | |
92 | |
93 if (cb == NULL) | |
94 cb = null_cmd_cb; | |
95 | |
96 g_hash_table_insert(cbs, answer, cb); | |
97 } | |
98 | |
99 void | |
100 msn_table_add_error(MsnTable *table, | |
101 char *answer, MsnErrorCb cb) | |
102 { | |
103 g_return_if_fail(table != NULL); | |
104 g_return_if_fail(answer != NULL); | |
105 | |
106 if (cb == NULL) | |
107 cb = null_error_cb; | |
108 | |
109 g_hash_table_insert(table->errors, answer, cb); | |
110 } | |
111 | |
112 void | |
113 msn_table_add_msg_type(MsnTable *table, | |
114 char *type, MsnMsgTypeCb cb) | |
115 { | |
116 g_return_if_fail(table != NULL); | |
117 g_return_if_fail(type != NULL); | |
118 g_return_if_fail(cb != NULL); | |
119 | |
120 #if 0 | |
121 if (cb == NULL) | |
122 cb = null_msg_cb; | |
123 #endif | |
124 | |
125 g_hash_table_insert(table->msgs, type, cb); | |
126 } |