aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet_chat_handle.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnunet_chat_handle.c')
-rw-r--r--src/gnunet_chat_handle.c80
1 files changed, 71 insertions, 9 deletions
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c
index a18e34e..6e2f32e 100644
--- a/src/gnunet_chat_handle.c
+++ b/src/gnunet_chat_handle.c
@@ -37,10 +37,11 @@ static void handle_arm_connection(void* cls, int connected) {
37 } 37 }
38} 38}
39 39
40
41struct GNUNET_CHAT_Handle* 40struct GNUNET_CHAT_Handle*
42GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle* cfg, 41GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle* cfg,
43 const char *name) { 42 const char *name,
43 GNUNET_CHAT_WarningCallback warn_cb,
44 void *warn_cls) {
44 if (!cfg) 45 if (!cfg)
45 return NULL; 46 return NULL;
46 47
@@ -142,14 +143,14 @@ GNUNET_CHAT_set_name (struct GNUNET_CHAT_Handle *handle,
142 if (!handle) 143 if (!handle)
143 return GNUNET_SYSERR; 144 return GNUNET_SYSERR;
144 145
145 return GNUNET_MESSENGER_set_name(handle, name); 146 return GNUNET_MESSENGER_set_name(handle->handles.messenger, name);
146} 147}
147 148
148const char* 149const char*
149GNUNET_CHAT_get_name (const struct GNUNET_CHAT_Handle *handle) 150GNUNET_CHAT_get_name (const struct GNUNET_CHAT_Handle *handle)
150{ 151{
151 if (!handle) 152 if (!handle)
152 return GNUNET_SYSERR; 153 return NULL;
153 154
154 return GNUNET_MESSENGER_get_name(handle->handles.messenger); 155 return GNUNET_MESSENGER_get_name(handle->handles.messenger);
155} 156}
@@ -158,26 +159,77 @@ const struct GNUNET_IDENTITY_PublicKey*
158GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle) 159GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle)
159{ 160{
160 if (!handle) 161 if (!handle)
161 return GNUNET_SYSERR; 162 return NULL;
162 163
163 return GNUNET_MESSENGER_get_key(handle->handles.messenger); 164 return GNUNET_MESSENGER_get_key(handle->handles.messenger);
164} 165}
165 166
167struct GNUNET_CHAT_IterateContacts
168{
169 struct GNUNET_CHAT_Handle *handle;
170 GNUNET_CHAT_ContactCallback callback;
171 void *cls;
172};
173
174static int
175handle_iterate_contacts(void *cls, const struct GNUNET_HashCode *key,
176 void *value)
177{
178 struct GNUNET_CHAT_IterateContacts *iterate = cls;
179 struct GNUNET_CHAT_Contact *contact = value;
180
181 if (!iterate->callback)
182 return GNUNET_YES;
183
184 return iterate->callback(iterate->cls, iterate->handle, contact);
185}
186
166int 187int
167GNUNET_CHAT_iterate_contacts (struct GNUNET_CHAT_Handle *handle, 188GNUNET_CHAT_iterate_contacts (struct GNUNET_CHAT_Handle *handle,
168 GNUNET_CHAT_ContactCallback callback, 189 GNUNET_CHAT_ContactCallback callback,
169 void *cls) 190 void *cls)
170{ 191{
171 return GNUNET_SYSERR; 192 if (!handle)
193 return GNUNET_SYSERR;
194
195 struct GNUNET_CHAT_IterateContacts iterate;
196 iterate.handle = handle;
197 iterate.callback = callback;
198 iterate.cls = cls;
199
200 return GNUNET_CONTAINER_multihashmap_iterate(handle->contacts,
201 handle_iterate_contacts,
202 &iterate);
172} 203}
173 204
174struct GNUNET_CHAT_Group* 205struct GNUNET_CHAT_Group*
175GNUNET_CHAT_group_create (struct GNUNET_CHAT_Handle *handle) 206GNUNET_CHAT_group_create (struct GNUNET_CHAT_Handle *handle,
207 const char *topic)
176{ 208{
177 if (!handle) 209 if (!handle)
178 return NULL; 210 return NULL;
179 211
180 return group_create(handle); 212 return group_create(handle, topic);
213}
214
215struct GNUNET_CHAT_IterateGroups
216{
217 struct GNUNET_CHAT_Handle *handle;
218 GNUNET_CHAT_GroupCallback callback;
219 void *cls;
220};
221
222static int
223handle_iterate_groups(void *cls, const struct GNUNET_HashCode *key,
224 void *value)
225{
226 struct GNUNET_CHAT_IterateGroups *iterate = cls;
227 struct GNUNET_CHAT_Group *group = value;
228
229 if (!iterate->callback)
230 return GNUNET_YES;
231
232 return iterate->callback(iterate->cls, iterate->handle, group);
181} 233}
182 234
183int 235int
@@ -185,5 +237,15 @@ GNUNET_CHAT_iterate_groups (struct GNUNET_CHAT_Handle *handle,
185 GNUNET_CHAT_GroupCallback callback, 237 GNUNET_CHAT_GroupCallback callback,
186 void *cls) 238 void *cls)
187{ 239{
188 return GNUNET_SYSERR; 240 if (!handle)
241 return GNUNET_SYSERR;
242
243 struct GNUNET_CHAT_IterateGroups iterate;
244 iterate.handle = handle;
245 iterate.callback = callback;
246 iterate.cls = cls;
247
248 return GNUNET_CONTAINER_multihashmap_iterate(handle->groups,
249 handle_iterate_contacts,
250 &iterate);
189} 251}