diff options
Diffstat (limited to 'src/gnunet_chat_context.c')
-rw-r--r-- | src/gnunet_chat_context.c | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c index 33a65d0..1124fd2 100644 --- a/src/gnunet_chat_context.c +++ b/src/gnunet_chat_context.c | |||
@@ -23,6 +23,8 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include "gnunet_chat_context.h" | 25 | #include "gnunet_chat_context.h" |
26 | #include "gnunet_chat_handle.h" | ||
27 | #include "gnunet_chat_util.h" | ||
26 | 28 | ||
27 | #include "gnunet_chat_context_intern.c" | 29 | #include "gnunet_chat_context_intern.c" |
28 | 30 | ||
@@ -68,3 +70,70 @@ context_destroy (struct GNUNET_CHAT_Context* context) | |||
68 | 70 | ||
69 | GNUNET_free(context); | 71 | GNUNET_free(context); |
70 | } | 72 | } |
73 | |||
74 | void | ||
75 | context_load_config (struct GNUNET_CHAT_Context *context) | ||
76 | { | ||
77 | const char *directory = context->handle->directory; | ||
78 | |||
79 | if (!directory) | ||
80 | return; | ||
81 | |||
82 | const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key( | ||
83 | context->room | ||
84 | ); | ||
85 | |||
86 | char* filename; | ||
87 | util_get_filename(directory, "chats", hash, &filename); | ||
88 | |||
89 | if (GNUNET_YES != GNUNET_DISK_file_test(filename)) | ||
90 | goto free_filename; | ||
91 | |||
92 | struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create(); | ||
93 | |||
94 | if (GNUNET_OK != GNUNET_CONFIGURATION_load(config, directory)) | ||
95 | goto destroy_config; | ||
96 | |||
97 | char* name = NULL; | ||
98 | |||
99 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string( | ||
100 | config, "chat", "name", &name)) | ||
101 | util_set_name_field(name, &(context->nick)); | ||
102 | |||
103 | if (name) | ||
104 | GNUNET_free(name); | ||
105 | |||
106 | destroy_config: | ||
107 | GNUNET_CONFIGURATION_destroy(config); | ||
108 | |||
109 | free_filename: | ||
110 | GNUNET_free(filename); | ||
111 | } | ||
112 | |||
113 | void | ||
114 | context_save_config (const struct GNUNET_CHAT_Context *context) | ||
115 | { | ||
116 | const char *directory = context->handle->directory; | ||
117 | |||
118 | if (!directory) | ||
119 | return; | ||
120 | |||
121 | const struct GNUNET_HashCode *hash = GNUNET_MESSENGER_room_get_key( | ||
122 | context->room | ||
123 | ); | ||
124 | |||
125 | struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create(); | ||
126 | |||
127 | if (context->nick) | ||
128 | GNUNET_CONFIGURATION_set_value_string( | ||
129 | config, "chat", "name", context->nick | ||
130 | ); | ||
131 | |||
132 | char* filename; | ||
133 | util_get_filename(directory, "chats", hash, &filename); | ||
134 | |||
135 | GNUNET_CONFIGURATION_write(config, filename); | ||
136 | GNUNET_CONFIGURATION_destroy(config); | ||
137 | |||
138 | GNUNET_free(filename); | ||
139 | } | ||