diff options
Diffstat (limited to 'src/gnunet_chat_handle_intern.c')
-rw-r--r-- | src/gnunet_chat_handle_intern.c | 157 |
1 files changed, 112 insertions, 45 deletions
diff --git a/src/gnunet_chat_handle_intern.c b/src/gnunet_chat_handle_intern.c index 282492c..a34c63e 100644 --- a/src/gnunet_chat_handle_intern.c +++ b/src/gnunet_chat_handle_intern.c | |||
@@ -24,8 +24,10 @@ | |||
24 | 24 | ||
25 | #include "gnunet_chat_contact.h" | 25 | #include "gnunet_chat_contact.h" |
26 | #include "gnunet_chat_context.h" | 26 | #include "gnunet_chat_context.h" |
27 | #include "gnunet_chat_file.h" | ||
27 | #include "gnunet_chat_group.h" | 28 | #include "gnunet_chat_group.h" |
28 | #include "gnunet_chat_handle.h" | 29 | #include "gnunet_chat_handle.h" |
30 | #include "gnunet_chat_invitation.h" | ||
29 | #include "gnunet_chat_message.h" | 31 | #include "gnunet_chat_message.h" |
30 | #include "gnunet_chat_util.h" | 32 | #include "gnunet_chat_util.h" |
31 | 33 | ||
@@ -67,79 +69,70 @@ notify_handle_fs_progress(void* cls, const struct GNUNET_FS_ProgressInfo* info) | |||
67 | 69 | ||
68 | switch (info->status) { | 70 | switch (info->status) { |
69 | case GNUNET_FS_STATUS_PUBLISH_START: { | 71 | case GNUNET_FS_STATUS_PUBLISH_START: { |
70 | /*publication_t* publication = (publication_t*) info->value.publish.cctx; | 72 | struct GNUNET_CHAT_File *file = info->value.publish.cctx; |
71 | publication->progress = 0.0f; | ||
72 | 73 | ||
73 | GNUNET_SCHEDULER_add_now(&CGTK_publication_progress, publication); | 74 | file->published = 0; |
74 | 75 | ||
75 | return publication;*/ | 76 | return file; |
76 | break; | ||
77 | } case GNUNET_FS_STATUS_PUBLISH_PROGRESS: { | 77 | } case GNUNET_FS_STATUS_PUBLISH_PROGRESS: { |
78 | /*publication_t* publication = (publication_t*) info->value.publish.cctx; | 78 | struct GNUNET_CHAT_File *file = info->value.publish.cctx; |
79 | publication->progress = 1.0f * info->value.publish.completed / info->value.publish.size; | ||
80 | 79 | ||
81 | GNUNET_SCHEDULER_add_now(&CGTK_publication_progress, publication); | 80 | file->published = info->value.publish.completed; |
82 | 81 | ||
83 | return publication;*/ | 82 | return file; |
84 | break; | ||
85 | } case GNUNET_FS_STATUS_PUBLISH_COMPLETED: { | 83 | } case GNUNET_FS_STATUS_PUBLISH_COMPLETED: { |
86 | /*publication_t* publication = (publication_t*) info->value.publish.cctx; | 84 | struct GNUNET_CHAT_File *file = info->value.publish.cctx; |
87 | publication->uri = GNUNET_FS_uri_dup(info->value.publish.specifics.completed.chk_uri); | 85 | |
88 | publication->progress = 1.0f; | 86 | file->uri = GNUNET_FS_uri_dup( |
87 | info->value.publish.specifics.completed.chk_uri | ||
88 | ); | ||
89 | 89 | ||
90 | GNUNET_SCHEDULER_add_now(&CGTK_publication_finish, publication);*/ | 90 | file->published = info->value.publish.size; |
91 | file->publish = NULL; | ||
91 | break; | 92 | break; |
92 | } case GNUNET_FS_STATUS_PUBLISH_ERROR: { | 93 | } case GNUNET_FS_STATUS_PUBLISH_ERROR: { |
93 | /*publication_t* publication = (publication_t*) info->value.publish.cctx; | ||
94 | |||
95 | GNUNET_SCHEDULER_add_now(&CGTK_publication_error, publication);*/ | ||
96 | break; | 94 | break; |
97 | } case GNUNET_FS_STATUS_DOWNLOAD_START: { | 95 | } case GNUNET_FS_STATUS_DOWNLOAD_START: { |
98 | /*request_t* request = (request_t*) info->value.download.cctx; | 96 | struct GNUNET_CHAT_File *file = info->value.download.cctx; |
99 | request->progress = 0.0f; | ||
100 | 97 | ||
101 | return request;*/ | 98 | file->downloaded = 0; |
102 | break; | 99 | |
100 | return file; | ||
103 | } case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: { | 101 | } case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: { |
104 | return info->value.download.cctx; | 102 | return info->value.download.cctx; |
105 | } case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: { | 103 | } case GNUNET_FS_STATUS_DOWNLOAD_INACTIVE: { |
106 | return info->value.download.cctx; | 104 | return info->value.download.cctx; |
107 | } case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: { | 105 | } case GNUNET_FS_STATUS_DOWNLOAD_PROGRESS: { |
108 | /*request_t* request = (request_t*) info->value.download.cctx; | 106 | struct GNUNET_CHAT_File *file = info->value.download.cctx; |
109 | request->progress = 1.0f * info->value.download.completed / info->value.download.size; | ||
110 | 107 | ||
111 | GNUNET_SCHEDULER_add_now(&CGTK_request_progress, request); | 108 | file->downloaded = info->value.download.completed; |
112 | 109 | ||
113 | return request;*/ | 110 | return file; |
114 | break; | ||
115 | } case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: { | 111 | } case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: { |
116 | /*request_t* request = (request_t*) info->value.download.cctx; | 112 | struct GNUNET_CHAT_File *file = info->value.download.cctx; |
117 | request->progress = 1.0f; | ||
118 | 113 | ||
119 | GNUNET_SCHEDULER_add_now(&CGTK_request_finish, request);*/ | 114 | file->downloaded = info->value.download.size; |
115 | file->download = NULL; | ||
120 | break; | 116 | break; |
121 | } case GNUNET_FS_STATUS_DOWNLOAD_ERROR: { | 117 | } case GNUNET_FS_STATUS_DOWNLOAD_ERROR: { |
122 | /*request_t *request = (request_t *) info->value.download.cctx; | ||
123 | |||
124 | GNUNET_SCHEDULER_add_now(&CGTK_request_error, request);*/ | ||
125 | break; | 118 | break; |
126 | } case GNUNET_FS_STATUS_UNINDEX_START: { | 119 | } case GNUNET_FS_STATUS_UNINDEX_START: { |
127 | /*publication_t* publication = (publication_t*) info->value.unindex.cctx; | 120 | struct GNUNET_CHAT_File *file = info->value.unindex.cctx; |
128 | publication->progress = 0.0f; | ||
129 | 121 | ||
130 | return publication;*/ | 122 | file->unindexed = 0; |
131 | break; | 123 | |
124 | return file; | ||
132 | } case GNUNET_FS_STATUS_UNINDEX_PROGRESS: { | 125 | } case GNUNET_FS_STATUS_UNINDEX_PROGRESS: { |
133 | /*publication_t* publication = (publication_t*) info->value.unindex.cctx; | 126 | struct GNUNET_CHAT_File *file = info->value.unindex.cctx; |
134 | publication->progress = 1.0f * info->value.unindex.completed / info->value.unindex.size; | ||
135 | 127 | ||
136 | return publication;*/ | 128 | file->unindexed = info->value.unindex.completed; |
137 | break; | 129 | |
130 | return file; | ||
138 | } case GNUNET_FS_STATUS_UNINDEX_COMPLETED: { | 131 | } case GNUNET_FS_STATUS_UNINDEX_COMPLETED: { |
139 | /*publication_t* publication = (publication_t*) info->value.unindex.cctx; | 132 | struct GNUNET_CHAT_File *file = info->value.unindex.cctx; |
140 | publication->progress = 1.0f; | ||
141 | 133 | ||
142 | GNUNET_SCHEDULER_add_now(&CGTK_publication_unindex_finish, publication);*/ | 134 | file->unindexed = info->value.unindex.size; |
135 | file->unindex = NULL; | ||
143 | break; | 136 | break; |
144 | } default: { | 137 | } default: { |
145 | break; | 138 | break; |
@@ -290,10 +283,45 @@ on_handle_message (void *cls, | |||
290 | ); | 283 | ); |
291 | 284 | ||
292 | if (message) | 285 | if (message) |
293 | goto process_callback; | 286 | return; |
294 | 287 | ||
295 | message = message_create_from_msg(context, hash, msg); | 288 | message = message_create_from_msg(context, hash, msg); |
296 | 289 | ||
290 | switch (msg->header.kind) | ||
291 | { | ||
292 | case GNUNET_MESSENGER_KIND_INVITE: | ||
293 | { | ||
294 | struct GNUNET_CHAT_Invitation *invitation = invitation_create_from_message( | ||
295 | context, &(msg->body.invite) | ||
296 | ); | ||
297 | |||
298 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( | ||
299 | context->invites, hash, invitation, | ||
300 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
301 | invitation_destroy(invitation); | ||
302 | break; | ||
303 | } | ||
304 | case GNUNET_MESSENGER_KIND_FILE: | ||
305 | { | ||
306 | GNUNET_CONTAINER_multihashmap_put( | ||
307 | context->files, hash, NULL, | ||
308 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST | ||
309 | ); | ||
310 | |||
311 | struct GNUNET_CHAT_File *file = file_create_from_message( | ||
312 | context->handle, &(msg->body.file) | ||
313 | ); | ||
314 | |||
315 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( | ||
316 | context->handle->files, &(file->hash), file, | ||
317 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | ||
318 | file_destroy(file); | ||
319 | break; | ||
320 | } | ||
321 | default: | ||
322 | break; | ||
323 | } | ||
324 | |||
297 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( | 325 | if (GNUNET_OK != GNUNET_CONTAINER_multihashmap_put( |
298 | context->messages, hash, message, | 326 | context->messages, hash, message, |
299 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) | 327 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST)) |
@@ -302,7 +330,46 @@ on_handle_message (void *cls, | |||
302 | return; | 330 | return; |
303 | } | 331 | } |
304 | 332 | ||
305 | process_callback: | ||
306 | if (handle->msg_cb) | 333 | if (handle->msg_cb) |
307 | handle->msg_cb(handle->msg_cls, context, message); | 334 | handle->msg_cb(handle->msg_cls, context, message); |
308 | } | 335 | } |
336 | |||
337 | int | ||
338 | it_destroy_handle_groups (GNUNET_UNUSED void *cls, | ||
339 | GNUNET_UNUSED const struct GNUNET_HashCode *key, | ||
340 | void *value) | ||
341 | { | ||
342 | struct GNUNET_CHAT_Group *group = value; | ||
343 | group_destroy(group); | ||
344 | return GNUNET_YES; | ||
345 | } | ||
346 | |||
347 | int | ||
348 | it_destroy_handle_contacts (GNUNET_UNUSED void *cls, | ||
349 | GNUNET_UNUSED const struct GNUNET_ShortHashCode *key, | ||
350 | void *value) | ||
351 | { | ||
352 | struct GNUNET_CHAT_Contact *contact = value; | ||
353 | contact_destroy(contact); | ||
354 | return GNUNET_YES; | ||
355 | } | ||
356 | |||
357 | int | ||
358 | it_destroy_handle_contexts (GNUNET_UNUSED void *cls, | ||
359 | GNUNET_UNUSED const struct GNUNET_HashCode *key, | ||
360 | void *value) | ||
361 | { | ||
362 | struct GNUNET_CHAT_Context *context = value; | ||
363 | context_destroy(context); | ||
364 | return GNUNET_YES; | ||
365 | } | ||
366 | |||
367 | int | ||
368 | it_destroy_handle_files (GNUNET_UNUSED void *cls, | ||
369 | GNUNET_UNUSED const struct GNUNET_HashCode *key, | ||
370 | void *value) | ||
371 | { | ||
372 | struct GNUNET_CHAT_File *file = value; | ||
373 | file_destroy(file); | ||
374 | return GNUNET_YES; | ||
375 | } | ||