aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet_chat_context.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnunet_chat_context.c')
-rw-r--r--src/gnunet_chat_context.c74
1 files changed, 71 insertions, 3 deletions
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c
index a95c869..f2fadc3 100644
--- a/src/gnunet_chat_context.c
+++ b/src/gnunet_chat_context.c
@@ -136,7 +136,7 @@ context_load_config (struct GNUNET_CHAT_Context *context)
136 136
137 struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create(); 137 struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create();
138 138
139 if (GNUNET_OK != GNUNET_CONFIGURATION_load(config, directory)) 139 if (GNUNET_OK != GNUNET_CONFIGURATION_load(config, filename))
140 goto destroy_config; 140 goto destroy_config;
141 141
142 char* name = NULL; 142 char* name = NULL;
@@ -167,19 +167,24 @@ context_save_config (const struct GNUNET_CHAT_Context *context)
167 if (!directory) 167 if (!directory)
168 return; 168 return;
169 169
170 const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key( 170 const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key(
171 context->room 171 context->room
172 ); 172 );
173 173
174 struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create(); 174 struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create();
175 175
176 if (context->room)
177 GNUNET_CONFIGURATION_set_value_string(
178 config, "chat", "key", GNUNET_h2s_full(key)
179 );
180
176 if (context->nick) 181 if (context->nick)
177 GNUNET_CONFIGURATION_set_value_string( 182 GNUNET_CONFIGURATION_set_value_string(
178 config, "chat", "name", context->nick 183 config, "chat", "name", context->nick
179 ); 184 );
180 185
181 char* filename; 186 char* filename;
182 util_get_filename(directory, "chats", hash, &filename); 187 util_get_filename(directory, "chats", key, &filename);
183 188
184 if (GNUNET_OK == GNUNET_DISK_directory_create_for_file(filename)) 189 if (GNUNET_OK == GNUNET_DISK_directory_create_for_file(filename))
185 GNUNET_CONFIGURATION_write(config, filename); 190 GNUNET_CONFIGURATION_write(config, filename);
@@ -188,3 +193,66 @@ context_save_config (const struct GNUNET_CHAT_Context *context)
188 193
189 GNUNET_free(filename); 194 GNUNET_free(filename);
190} 195}
196
197enum GNUNET_GenericReturnValue
198callback_scan_for_configs (void *cls,
199 const char *filename)
200{
201 struct GNUNET_CHAT_Handle *handle = (struct GNUNET_CHAT_Handle*) cls;
202 struct GNUNET_PeerIdentity door;
203 struct GNUNET_HashCode key;
204
205 memset(&door, 0, sizeof(door));
206 memset(&key, 0, sizeof(key));
207
208 if ((!filename) ||
209 (GNUNET_OK != GNUNET_CRYPTO_get_peer_identity(handle->cfg, &door)))
210 return GNUNET_YES;
211
212 struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create();
213
214 if (GNUNET_OK != GNUNET_CONFIGURATION_load(config, filename))
215 goto destroy_config;
216
217 char* key_value = NULL;
218
219 if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(
220 config, "chat", "key", &key_value)) &&
221 (GNUNET_OK == GNUNET_CRYPTO_hash_from_string(key_value, &key)))
222 GNUNET_MESSENGER_enter_room(
223 handle->messenger, &door, &key
224 );
225
226 if (key_value)
227 GNUNET_free(key_value);
228
229destroy_config:
230 GNUNET_CONFIGURATION_destroy(config);
231 return GNUNET_YES;
232}
233
234void
235context_scan_configs (struct GNUNET_CHAT_Handle *handle)
236{
237 GNUNET_assert((handle) && (handle->messenger));
238
239 const char *directory = handle->directory;
240
241 if (!directory)
242 return;
243
244 char* dirname;
245 util_get_dirname(handle->directory, "chats", &dirname);
246
247 if (GNUNET_YES != GNUNET_DISK_directory_test(dirname, GNUNET_YES))
248 goto free_dirname;
249
250 GNUNET_DISK_directory_scan(
251 dirname,
252 callback_scan_for_configs,
253 handle
254 );
255
256free_dirname:
257 GNUNET_free(dirname);
258}