diff options
Diffstat (limited to 'src/gnunet_chat_group.c')
-rw-r--r-- | src/gnunet_chat_group.c | 89 |
1 files changed, 3 insertions, 86 deletions
diff --git a/src/gnunet_chat_group.c b/src/gnunet_chat_group.c index 7fcc98e..d102893 100644 --- a/src/gnunet_chat_group.c +++ b/src/gnunet_chat_group.c | |||
@@ -38,8 +38,6 @@ group_create_from_context (struct GNUNET_CHAT_Handle *handle, | |||
38 | group->handle = handle; | 38 | group->handle = handle; |
39 | group->context = context; | 39 | group->context = context; |
40 | 40 | ||
41 | group->topic = NULL; | ||
42 | |||
43 | group->announcement = NULL; | 41 | group->announcement = NULL; |
44 | group->search = NULL; | 42 | group->search = NULL; |
45 | 43 | ||
@@ -64,9 +62,6 @@ group_destroy (struct GNUNET_CHAT_Group* group) | |||
64 | if (group->announcement) | 62 | if (group->announcement) |
65 | GNUNET_REGEX_announce_cancel(group->announcement); | 63 | GNUNET_REGEX_announce_cancel(group->announcement); |
66 | 64 | ||
67 | if (group->topic) | ||
68 | GNUNET_free(group->topic); | ||
69 | |||
70 | GNUNET_free(group); | 65 | GNUNET_free(group); |
71 | } | 66 | } |
72 | 67 | ||
@@ -74,7 +69,8 @@ void | |||
74 | group_publish (struct GNUNET_CHAT_Group* group) | 69 | group_publish (struct GNUNET_CHAT_Group* group) |
75 | { | 70 | { |
76 | GNUNET_assert((group) && | 71 | GNUNET_assert((group) && |
77 | (group->topic) && | 72 | (group->context) && |
73 | (group->context->topic) && | ||
78 | (group->handle) && | 74 | (group->handle) && |
79 | (group->handle->cfg)); | 75 | (group->handle->cfg)); |
80 | 76 | ||
@@ -82,7 +78,7 @@ group_publish (struct GNUNET_CHAT_Group* group) | |||
82 | GNUNET_asprintf ( | 78 | GNUNET_asprintf ( |
83 | &topic, | 79 | &topic, |
84 | "GNUNET_CHAT_%s", | 80 | "GNUNET_CHAT_%s", |
85 | group->topic | 81 | group->context->topic |
86 | ); | 82 | ); |
87 | 83 | ||
88 | group->announcement = GNUNET_REGEX_announce( | 84 | group->announcement = GNUNET_REGEX_announce( |
@@ -98,82 +94,3 @@ group_publish (struct GNUNET_CHAT_Group* group) | |||
98 | 94 | ||
99 | GNUNET_free(topic); | 95 | GNUNET_free(topic); |
100 | } | 96 | } |
101 | |||
102 | void | ||
103 | group_load_config (struct GNUNET_CHAT_Group *group) | ||
104 | { | ||
105 | GNUNET_assert((group) && (group->handle)); | ||
106 | |||
107 | const char *directory = handle_get_directory(group->handle); | ||
108 | |||
109 | if ((!directory) || (!(group->context))) | ||
110 | return; | ||
111 | |||
112 | const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key( | ||
113 | group->context->room | ||
114 | ); | ||
115 | |||
116 | char* filename; | ||
117 | util_get_filename(directory, "groups", key, &filename); | ||
118 | |||
119 | if (GNUNET_YES != GNUNET_DISK_file_test(filename)) | ||
120 | goto free_filename; | ||
121 | |||
122 | struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create(); | ||
123 | |||
124 | if (GNUNET_OK != GNUNET_CONFIGURATION_load(config, filename)) | ||
125 | goto destroy_config; | ||
126 | |||
127 | char* name = NULL; | ||
128 | |||
129 | if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string( | ||
130 | config, "group", "topic", &name)) | ||
131 | util_set_name_field(name, &(group->topic)); | ||
132 | |||
133 | if (name) | ||
134 | GNUNET_free(name); | ||
135 | |||
136 | destroy_config: | ||
137 | GNUNET_CONFIGURATION_destroy(config); | ||
138 | |||
139 | free_filename: | ||
140 | GNUNET_free(filename); | ||
141 | } | ||
142 | |||
143 | void | ||
144 | group_save_config (const struct GNUNET_CHAT_Group *group) | ||
145 | { | ||
146 | GNUNET_assert((group) && (group->handle)); | ||
147 | |||
148 | const char *directory = handle_get_directory(group->handle); | ||
149 | |||
150 | if ((!directory) || (!(group->context))) | ||
151 | return; | ||
152 | |||
153 | const struct GNUNET_HashCode *key = GNUNET_MESSENGER_room_get_key( | ||
154 | group->context->room | ||
155 | ); | ||
156 | |||
157 | struct GNUNET_CONFIGURATION_Handle *config = GNUNET_CONFIGURATION_create(); | ||
158 | |||
159 | if (group->topic) | ||
160 | { | ||
161 | struct GNUNET_HashCode topic_hash; | ||
162 | GNUNET_CRYPTO_hash(group->topic, strlen(group->topic), &topic_hash); | ||
163 | |||
164 | if (0 == GNUNET_memcmp(key, &topic_hash)) | ||
165 | GNUNET_CONFIGURATION_set_value_string( | ||
166 | config, "group", "topic", group->topic | ||
167 | ); | ||
168 | } | ||
169 | |||
170 | char* filename; | ||
171 | util_get_filename(directory, "groups", key, &filename); | ||
172 | |||
173 | if (GNUNET_OK == GNUNET_DISK_directory_create_for_file(filename)) | ||
174 | GNUNET_CONFIGURATION_write(config, filename); | ||
175 | |||
176 | GNUNET_CONFIGURATION_destroy(config); | ||
177 | |||
178 | GNUNET_free(filename); | ||
179 | } | ||