diff options
Diffstat (limited to 'src/gnunet_chat_handle.c')
-rw-r--r-- | src/gnunet_chat_handle.c | 185 |
1 files changed, 111 insertions, 74 deletions
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c index f4e86b2..57e0043 100644 --- a/src/gnunet_chat_handle.c +++ b/src/gnunet_chat_handle.c | |||
@@ -29,7 +29,6 @@ | |||
29 | struct GNUNET_CHAT_Handle* | 29 | struct GNUNET_CHAT_Handle* |
30 | handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, | 30 | handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, |
31 | const char *directory, | 31 | const char *directory, |
32 | const char *name, | ||
33 | GNUNET_CHAT_ContextMessageCallback msg_cb, | 32 | GNUNET_CHAT_ContextMessageCallback msg_cb, |
34 | void *msg_cls) | 33 | void *msg_cls) |
35 | { | 34 | { |
@@ -54,13 +53,15 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, | |||
54 | handle->msg_cb = msg_cb; | 53 | handle->msg_cb = msg_cb; |
55 | handle->msg_cls = msg_cls; | 54 | handle->msg_cls = msg_cls; |
56 | 55 | ||
57 | handle->identities_head = NULL; | 56 | handle->accounts_head = NULL; |
58 | handle->identities_tail = NULL; | 57 | handle->accounts_tail = NULL; |
59 | 58 | ||
60 | handle->files = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | 59 | handle->current = NULL; |
61 | handle->contexts = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | 60 | |
62 | handle->contacts = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO); | 61 | handle->files = NULL; |
63 | handle->groups = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | 62 | handle->contexts = NULL; |
63 | handle->contacts = NULL; | ||
64 | handle->groups = NULL; | ||
64 | 65 | ||
65 | handle->arm = GNUNET_ARM_connect( | 66 | handle->arm = GNUNET_ARM_connect( |
66 | handle->cfg, | 67 | handle->cfg, |
@@ -70,39 +71,17 @@ handle_create_from_config (const struct GNUNET_CONFIGURATION_Handle* cfg, | |||
70 | if (handle->arm) | 71 | if (handle->arm) |
71 | on_handle_arm_connection(handle, GNUNET_NO); | 72 | on_handle_arm_connection(handle, GNUNET_NO); |
72 | 73 | ||
73 | char* fs_client_name = NULL; | ||
74 | GNUNET_asprintf ( | ||
75 | &fs_client_name, | ||
76 | "GNUNET_CHAT_%s%s", | ||
77 | name? "_" : "anonymous", | ||
78 | name? name : "" | ||
79 | ); | ||
80 | |||
81 | handle->fs = GNUNET_FS_start( | ||
82 | handle->cfg, fs_client_name, | ||
83 | notify_handle_fs_progress, handle, | ||
84 | GNUNET_FS_FLAGS_NONE, | ||
85 | GNUNET_FS_OPTIONS_END | ||
86 | ); | ||
87 | |||
88 | GNUNET_free(fs_client_name); | ||
89 | |||
90 | handle->identity = GNUNET_IDENTITY_connect( | 74 | handle->identity = GNUNET_IDENTITY_connect( |
91 | handle->cfg, | 75 | handle->cfg, |
92 | on_handle_gnunet_identity, | 76 | on_handle_gnunet_identity, |
93 | handle | 77 | handle |
94 | ); | 78 | ); |
95 | 79 | ||
96 | handle->messenger = GNUNET_MESSENGER_connect( | 80 | handle->fs = NULL; |
97 | handle->cfg, name, | 81 | handle->messenger = NULL; |
98 | on_handle_identity, handle, | ||
99 | on_handle_message, handle | ||
100 | ); | ||
101 | 82 | ||
102 | handle->public_key = NULL; | 83 | handle->public_key = NULL; |
103 | handle->user_pointer = NULL; | 84 | handle->user_pointer = NULL; |
104 | |||
105 | handle_update_key(handle); | ||
106 | return handle; | 85 | return handle; |
107 | } | 86 | } |
108 | 87 | ||
@@ -129,66 +108,35 @@ handle_update_key (struct GNUNET_CHAT_Handle *handle) | |||
129 | void | 108 | void |
130 | handle_destroy (struct GNUNET_CHAT_Handle *handle) | 109 | handle_destroy (struct GNUNET_CHAT_Handle *handle) |
131 | { | 110 | { |
132 | GNUNET_assert((handle) && | 111 | GNUNET_assert(handle); |
133 | (handle->groups) && | ||
134 | (handle->contacts) && | ||
135 | (handle->contexts) && | ||
136 | (handle->files)); | ||
137 | 112 | ||
138 | if (handle->shutdown_hook) | 113 | if (handle->shutdown_hook) |
139 | GNUNET_SCHEDULER_cancel(handle->shutdown_hook); | 114 | GNUNET_SCHEDULER_cancel(handle->shutdown_hook); |
140 | 115 | ||
141 | GNUNET_CONTAINER_multihashmap_iterate( | 116 | if (handle->current) |
142 | handle->groups, it_destroy_handle_groups, NULL | 117 | handle_disconnect(handle); |
143 | ); | ||
144 | |||
145 | GNUNET_CONTAINER_multishortmap_iterate( | ||
146 | handle->contacts, it_destroy_handle_contacts, NULL | ||
147 | ); | ||
148 | |||
149 | GNUNET_CONTAINER_multihashmap_iterate( | ||
150 | handle->contexts, it_destroy_handle_contexts, NULL | ||
151 | ); | ||
152 | |||
153 | if (handle->public_key) | ||
154 | GNUNET_free(handle->public_key); | ||
155 | |||
156 | if (handle->messenger) | ||
157 | GNUNET_MESSENGER_disconnect(handle->messenger); | ||
158 | 118 | ||
159 | if (handle->identity) | 119 | if (handle->identity) |
160 | GNUNET_IDENTITY_disconnect(handle->identity); | 120 | GNUNET_IDENTITY_disconnect(handle->identity); |
161 | 121 | ||
162 | if (handle->fs) | ||
163 | GNUNET_FS_stop(handle->fs); | ||
164 | |||
165 | if (handle->arm) | 122 | if (handle->arm) |
166 | GNUNET_ARM_disconnect(handle->arm); | 123 | GNUNET_ARM_disconnect(handle->arm); |
167 | 124 | ||
168 | GNUNET_CONTAINER_multihashmap_iterate( | 125 | struct GNUNET_CHAT_InternalAccounts *accounts; |
169 | handle->files, it_destroy_handle_files, NULL | 126 | while (handle->accounts_head) |
170 | ); | ||
171 | |||
172 | GNUNET_CONTAINER_multihashmap_destroy(handle->groups); | ||
173 | GNUNET_CONTAINER_multishortmap_destroy(handle->contacts); | ||
174 | GNUNET_CONTAINER_multihashmap_destroy(handle->contexts); | ||
175 | GNUNET_CONTAINER_multihashmap_destroy(handle->files); | ||
176 | |||
177 | struct GNUNET_CHAT_InternalIdentities *identities; | ||
178 | while (handle->identities_head) | ||
179 | { | 127 | { |
180 | identities = handle->identities_head; | 128 | accounts = handle->accounts_head; |
181 | 129 | ||
182 | if (identities->name) | 130 | if (accounts->account) |
183 | GNUNET_free(identities->name); | 131 | account_destroy(accounts->account); |
184 | 132 | ||
185 | GNUNET_CONTAINER_DLL_remove( | 133 | GNUNET_CONTAINER_DLL_remove( |
186 | handle->identities_head, | 134 | handle->accounts_head, |
187 | handle->identities_tail, | 135 | handle->accounts_tail, |
188 | identities | 136 | accounts |
189 | ); | 137 | ); |
190 | 138 | ||
191 | GNUNET_free(identities); | 139 | GNUNET_free(accounts); |
192 | } | 140 | } |
193 | 141 | ||
194 | if (handle->directory) | 142 | if (handle->directory) |
@@ -215,6 +163,95 @@ handle_destroy (struct GNUNET_CHAT_Handle *handle) | |||
215 | } | 163 | } |
216 | 164 | ||
217 | void | 165 | void |
166 | handle_connect (struct GNUNET_CHAT_Handle *handle, | ||
167 | const struct GNUNET_CHAT_Account *account) | ||
168 | { | ||
169 | GNUNET_assert((handle) && (account) && | ||
170 | (!(handle->current)) && | ||
171 | (!(handle->groups)) && | ||
172 | (!(handle->contacts)) && | ||
173 | (!(handle->contexts)) && | ||
174 | (!(handle->files))); | ||
175 | |||
176 | handle->files = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | ||
177 | handle->contexts = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | ||
178 | handle->contacts = GNUNET_CONTAINER_multishortmap_create(8, GNUNET_NO); | ||
179 | handle->groups = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | ||
180 | |||
181 | const char *name = account->name; | ||
182 | |||
183 | char* fs_client_name = NULL; | ||
184 | GNUNET_asprintf ( | ||
185 | &fs_client_name, | ||
186 | "GNUNET_CHAT_%s%s", | ||
187 | name? "_" : "anonymous", | ||
188 | name? name : "" | ||
189 | ); | ||
190 | |||
191 | handle->fs = GNUNET_FS_start( | ||
192 | handle->cfg, fs_client_name, | ||
193 | notify_handle_fs_progress, handle, | ||
194 | GNUNET_FS_FLAGS_NONE, | ||
195 | GNUNET_FS_OPTIONS_END | ||
196 | ); | ||
197 | |||
198 | GNUNET_free(fs_client_name); | ||
199 | |||
200 | handle->messenger = GNUNET_MESSENGER_connect( | ||
201 | handle->cfg, name, | ||
202 | on_handle_identity, handle, | ||
203 | on_handle_message, handle | ||
204 | ); | ||
205 | |||
206 | handle->current = account; | ||
207 | handle_update_key(handle); | ||
208 | } | ||
209 | |||
210 | void | ||
211 | handle_disconnect (struct GNUNET_CHAT_Handle *handle) | ||
212 | { | ||
213 | GNUNET_assert((handle) && | ||
214 | (handle->current) && | ||
215 | (handle->groups) && | ||
216 | (handle->contacts) && | ||
217 | (handle->contexts) && | ||
218 | (handle->files)); | ||
219 | |||
220 | GNUNET_CONTAINER_multihashmap_iterate( | ||
221 | handle->groups, it_destroy_handle_groups, NULL | ||
222 | ); | ||
223 | |||
224 | GNUNET_CONTAINER_multishortmap_iterate( | ||
225 | handle->contacts, it_destroy_handle_contacts, NULL | ||
226 | ); | ||
227 | |||
228 | GNUNET_CONTAINER_multihashmap_iterate( | ||
229 | handle->contexts, it_destroy_handle_contexts, NULL | ||
230 | ); | ||
231 | |||
232 | if (handle->messenger) | ||
233 | GNUNET_MESSENGER_disconnect(handle->messenger); | ||
234 | |||
235 | if (handle->fs) | ||
236 | GNUNET_FS_stop(handle->fs); | ||
237 | |||
238 | GNUNET_CONTAINER_multihashmap_iterate( | ||
239 | handle->files, it_destroy_handle_files, NULL | ||
240 | ); | ||
241 | |||
242 | handle->fs = NULL; | ||
243 | handle->messenger = NULL; | ||
244 | |||
245 | GNUNET_CONTAINER_multihashmap_destroy(handle->groups); | ||
246 | GNUNET_CONTAINER_multishortmap_destroy(handle->contacts); | ||
247 | GNUNET_CONTAINER_multihashmap_destroy(handle->contexts); | ||
248 | GNUNET_CONTAINER_multihashmap_destroy(handle->files); | ||
249 | |||
250 | handle->current = NULL; | ||
251 | handle_update_key(handle); | ||
252 | } | ||
253 | |||
254 | void | ||
218 | handle_send_internal_message (struct GNUNET_CHAT_Handle *handle, | 255 | handle_send_internal_message (struct GNUNET_CHAT_Handle *handle, |
219 | struct GNUNET_CHAT_Context *context, | 256 | struct GNUNET_CHAT_Context *context, |
220 | enum GNUNET_CHAT_MessageFlag flag, | 257 | enum GNUNET_CHAT_MessageFlag flag, |