diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gnunet_chat_contact.c | 124 | ||||
-rw-r--r-- | src/gnunet_chat_contact.h | 27 | ||||
-rw-r--r-- | src/gnunet_chat_context.c | 146 | ||||
-rw-r--r-- | src/gnunet_chat_context.h | 33 | ||||
-rw-r--r-- | src/gnunet_chat_file.c | 58 | ||||
-rw-r--r-- | src/gnunet_chat_file.h | 19 | ||||
-rw-r--r-- | src/gnunet_chat_group.c | 179 | ||||
-rw-r--r-- | src/gnunet_chat_group.h | 25 | ||||
-rw-r--r-- | src/gnunet_chat_handle.c | 170 | ||||
-rw-r--r-- | src/gnunet_chat_handle.h | 33 | ||||
-rw-r--r-- | src/gnunet_chat_message.c | 64 | ||||
-rw-r--r-- | src/gnunet_chat_message.h | 18 |
12 files changed, 896 insertions, 0 deletions
diff --git a/src/gnunet_chat_contact.c b/src/gnunet_chat_contact.c new file mode 100644 index 0000000..1fec6af --- /dev/null +++ b/src/gnunet_chat_contact.c | |||
@@ -0,0 +1,124 @@ | |||
1 | /* | ||
2 | * @author Tobias Frisch | ||
3 | * @file gnunet_chat_contact.c | ||
4 | */ | ||
5 | |||
6 | #include "gnunet_chat_lib.h" | ||
7 | #include "gnunet_chat_contact.h" | ||
8 | #include "gnunet_chat_handle.h" | ||
9 | |||
10 | struct GNUNET_CHAT_Contact* | ||
11 | contact_create (struct GNUNET_CHAT_Handle *handle) | ||
12 | { | ||
13 | struct GNUNET_CHAT_Contact* contact = GNUNET_new(struct GNUNET_CHAT_Contact); | ||
14 | |||
15 | contact->handle = handle; | ||
16 | contact->context = context_create(handle, NULL); // TODO: check for existing context? | ||
17 | |||
18 | contact->contact = NULL; | ||
19 | contact->nick = NULL; | ||
20 | |||
21 | if (!contact->context) | ||
22 | { | ||
23 | contact_destroy (contact); | ||
24 | return NULL; | ||
25 | } | ||
26 | |||
27 | const struct GNUNET_HashCode *key = context_get_key(contact->context); | ||
28 | |||
29 | const int result = GNUNET_CONTAINER_multihashmap_put( | ||
30 | handle->contacts, | ||
31 | key, | ||
32 | contact, | ||
33 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST | ||
34 | ); | ||
35 | |||
36 | if (GNUNET_OK != result) { | ||
37 | contact_destroy (contact); | ||
38 | return NULL; | ||
39 | } | ||
40 | |||
41 | return contact; | ||
42 | } | ||
43 | |||
44 | void | ||
45 | contact_destroy (struct GNUNET_CHAT_Contact *contact) | ||
46 | { | ||
47 | if (!contact->context) | ||
48 | goto skip_context; | ||
49 | |||
50 | struct GNUNET_CHAT_Handle *handle = contact->handle; | ||
51 | const struct GNUNET_HashCode *key = context_get_key(contact->context); | ||
52 | |||
53 | GNUNET_CONTAINER_multihashmap_remove( | ||
54 | handle->contacts, | ||
55 | key, | ||
56 | contact | ||
57 | ); | ||
58 | |||
59 | context_destroy(contact->context); | ||
60 | |||
61 | skip_context: | ||
62 | if (contact->nick) | ||
63 | GNUNET_free(contact->nick); | ||
64 | } | ||
65 | |||
66 | int | ||
67 | GNUNET_CHAT_contact_delete (struct GNUNET_CHAT_Contact *contact) | ||
68 | { | ||
69 | if (!contact) | ||
70 | return GNUNET_SYSERR; | ||
71 | |||
72 | if (contact->context) | ||
73 | GNUNET_MESSENGER_close_room(contact->context->room); | ||
74 | |||
75 | contact_destroy(contact); | ||
76 | return GNUNET_OK; | ||
77 | } | ||
78 | |||
79 | void | ||
80 | GNUNET_CHAT_contact_set_blocking (struct GNUNET_CHAT_Contact *contact, | ||
81 | int blocking) | ||
82 | { | ||
83 | //TODO | ||
84 | } | ||
85 | |||
86 | int | ||
87 | GNUNET_CHAT_contact_is_blocking (const struct GNUNET_CHAT_Contact *contact) | ||
88 | { | ||
89 | return GNUNET_NO; | ||
90 | } | ||
91 | |||
92 | void | ||
93 | GNUNET_CHAT_contact_set_name (struct GNUNET_CHAT_Contact *contact, | ||
94 | const char *name) | ||
95 | { | ||
96 | if (!contact) | ||
97 | return; | ||
98 | |||
99 | if (contact->nick) | ||
100 | GNUNET_free(contact->nick); | ||
101 | |||
102 | contact->nick = name? GNUNET_strdup(name) : NULL; | ||
103 | } | ||
104 | |||
105 | const char* | ||
106 | GNUNET_CHAT_contact_get_name (const struct GNUNET_CHAT_Contact *contact) | ||
107 | { | ||
108 | if (!contact) | ||
109 | return NULL; | ||
110 | |||
111 | if (contact->nick) | ||
112 | return contact->nick; | ||
113 | |||
114 | return GNUNET_MESSENGER_contact_get_name(contact->contact); | ||
115 | } | ||
116 | |||
117 | struct GNUNET_CHAT_Context* | ||
118 | GNUNET_CHAT_contact_get_context (struct GNUNET_CHAT_Contact *contact) | ||
119 | { | ||
120 | if (!contact) | ||
121 | return NULL; | ||
122 | |||
123 | return contact->context; | ||
124 | } | ||
diff --git a/src/gnunet_chat_contact.h b/src/gnunet_chat_contact.h new file mode 100644 index 0000000..a8e28a1 --- /dev/null +++ b/src/gnunet_chat_contact.h | |||
@@ -0,0 +1,27 @@ | |||
1 | /* | ||
2 | * @author Tobias Frisch | ||
3 | * @file gnunet_chat_contact.h | ||
4 | */ | ||
5 | |||
6 | #ifndef GNUNET_CHAT_CONTACT_H_ | ||
7 | #define GNUNET_CHAT_CONTACT_H_ | ||
8 | |||
9 | #include "gnunet_chat_context.h" | ||
10 | |||
11 | struct GNUNET_CHAT_Contact | ||
12 | { | ||
13 | struct GNUNET_CHAT_Handle *handle; | ||
14 | struct GNUNET_CHAT_Context *context; | ||
15 | |||
16 | struct GNUNET_MESSENGER_Contact *contact; | ||
17 | |||
18 | char *nick; | ||
19 | }; | ||
20 | |||
21 | struct GNUNET_CHAT_Contact* | ||
22 | contact_create (struct GNUNET_CHAT_Handle *handle); | ||
23 | |||
24 | void | ||
25 | contact_destroy (struct GNUNET_CHAT_Contact *contact); | ||
26 | |||
27 | #endif /* GNUNET_CHAT_CONTACT_H_ */ | ||
diff --git a/src/gnunet_chat_context.c b/src/gnunet_chat_context.c new file mode 100644 index 0000000..47eb44f --- /dev/null +++ b/src/gnunet_chat_context.c | |||
@@ -0,0 +1,146 @@ | |||
1 | /* | ||
2 | * @author Tobias Frisch | ||
3 | * @file gnunet_chat_context.c | ||
4 | */ | ||
5 | |||
6 | #include "gnunet_chat_lib.h" | ||
7 | #include "gnunet_chat_context.h" | ||
8 | #include "gnunet_chat_handle.h" | ||
9 | |||
10 | struct GNUNET_CHAT_Context* | ||
11 | context_create (struct GNUNET_CHAT_Handle *handle, | ||
12 | const struct GNUNET_HashCode *key) | ||
13 | { | ||
14 | struct GNUNET_MESSENGER_Handle *messenger = handle->handles.messenger; | ||
15 | |||
16 | struct GNUNET_HashCode _room_key; | ||
17 | const struct GNUNET_HashCode *room_key; | ||
18 | |||
19 | if (key) | ||
20 | room_key = key; | ||
21 | else | ||
22 | { | ||
23 | GNUNET_CRYPTO_random_block( | ||
24 | GNUNET_CRYPTO_QUALITY_WEAK, | ||
25 | &_room_key, | ||
26 | sizeof(_room_key) | ||
27 | ); | ||
28 | |||
29 | room_key = &_room_key; | ||
30 | } | ||
31 | |||
32 | struct GNUNET_MESSENGER_Room *room = GNUNET_MESSENGER_open_room( | ||
33 | messenger, room_key | ||
34 | ); | ||
35 | |||
36 | if (!room) | ||
37 | return NULL; | ||
38 | |||
39 | struct GNUNET_CHAT_Context* context = GNUNET_new(struct GNUNET_CHAT_Context); | ||
40 | |||
41 | context->handle = handle; | ||
42 | context->room = room; | ||
43 | |||
44 | GNUNET_memcpy(&(context->key), room_key, sizeof(_room_key)); | ||
45 | |||
46 | return context; | ||
47 | } | ||
48 | |||
49 | void | ||
50 | context_destroy (struct GNUNET_CHAT_Context* context) | ||
51 | { | ||
52 | GNUNET_free(context); | ||
53 | } | ||
54 | |||
55 | const struct GNUNET_HashCode* | ||
56 | context_get_key (struct GNUNET_CHAT_Context* context) | ||
57 | { | ||
58 | return &(context->key); | ||
59 | } | ||
60 | |||
61 | void | ||
62 | GNUNET_CHAT_context_send_text (struct GNUNET_CHAT_Context *context, | ||
63 | const char *text) | ||
64 | { | ||
65 | if (!context) | ||
66 | return; | ||
67 | |||
68 | struct GNUNET_MESSENGER_Message message; | ||
69 | message.header.kind = GNUNET_MESSENGER_KIND_TEXT; | ||
70 | message.body.text.text = text; | ||
71 | |||
72 | GNUNET_MESSENGER_send_message(context->room, &message, NULL); | ||
73 | } | ||
74 | |||
75 | void | ||
76 | GNUNET_CHAT_context_send_file (struct GNUNET_CHAT_Context *context, | ||
77 | const char *path) | ||
78 | { | ||
79 | //TODO: generate key, hash file, encrypt file, upload file, share uri & info | ||
80 | } | ||
81 | |||
82 | void | ||
83 | GNUNET_CHAT_context_send_uri (struct GNUNET_CHAT_Context *context, | ||
84 | const char *uri) | ||
85 | { | ||
86 | if (!context) | ||
87 | return; | ||
88 | |||
89 | struct GNUNET_MESSENGER_Message message; | ||
90 | message.header.kind = GNUNET_MESSENGER_KIND_FILE; | ||
91 | |||
92 | memset(&(message.body.file.key), 0, sizeof(message.body.file.key)); | ||
93 | |||
94 | message.body.file.hash; // TODO: download & hash | ||
95 | GNUNET_memcpy(message.body.file.name, "", 1); // TODO: cut from uri or get from download? | ||
96 | message.body.file.uri = uri; | ||
97 | |||
98 | GNUNET_MESSENGER_send_message(context->room, &message, NULL); | ||
99 | } | ||
100 | |||
101 | void | ||
102 | GNUNET_CHAT_context_share_file (struct GNUNET_CHAT_Context *context, | ||
103 | const struct GNUNET_CHAT_File *file) | ||
104 | { | ||
105 | //TODO: send copied message basically | ||
106 | } | ||
107 | |||
108 | void | ||
109 | GNUNET_CHAT_context_delete_message (struct GNUNET_CHAT_Context *context, | ||
110 | const struct GNUNET_HashCode *hash, | ||
111 | struct GNUNET_TIME_Relative delay) | ||
112 | { | ||
113 | if (!context) | ||
114 | return; | ||
115 | |||
116 | struct GNUNET_MESSENGER_Message message; | ||
117 | message.header.kind = GNUNET_MESSENGER_KIND_TEXT; | ||
118 | GNUNET_memcpy(&(message.body.delete.hash), hash, sizeof(*hash)); | ||
119 | message.body.delete.delay = GNUNET_TIME_relative_hton(delay); | ||
120 | |||
121 | GNUNET_MESSENGER_send_message(context->room, &message, NULL); | ||
122 | } | ||
123 | |||
124 | const struct GNUNET_CHAT_Message* | ||
125 | GNUNET_CHAT_context_get_message (struct GNUNET_CHAT_Context *context, | ||
126 | const struct GNUNET_HashCode *hash) | ||
127 | { | ||
128 | if (!context) | ||
129 | return NULL; | ||
130 | |||
131 | struct GNUNET_MESSENGER_Message *message = GNUNET_MESSENGER_get_message( | ||
132 | context->room, hash | ||
133 | ); | ||
134 | |||
135 | //TODO: convert messenger-message to chat-message | ||
136 | |||
137 | return NULL; | ||
138 | } | ||
139 | |||
140 | int | ||
141 | GNUNET_CHAT_context_iterate_messages (struct GNUNET_CHAT_Context *context, | ||
142 | GNUNET_CHAT_ContextMessageCallback callback, | ||
143 | void *cls) | ||
144 | { | ||
145 | return GNUNET_SYSERR; | ||
146 | } | ||
diff --git a/src/gnunet_chat_context.h b/src/gnunet_chat_context.h new file mode 100644 index 0000000..0994004 --- /dev/null +++ b/src/gnunet_chat_context.h | |||
@@ -0,0 +1,33 @@ | |||
1 | /* | ||
2 | * @author Tobias Frisch | ||
3 | * @file gnunet_chat_context.h | ||
4 | */ | ||
5 | |||
6 | #ifndef GNUNET_CHAT_CONTEXT_H_ | ||
7 | #define GNUNET_CHAT_CONTEXT_H_ | ||
8 | |||
9 | #include <gnunet/platform.h> | ||
10 | #include <gnunet/gnunet_messenger_service.h> | ||
11 | #include <gnunet/gnunet_util_lib.h> | ||
12 | |||
13 | struct GNUNET_CHAT_Handle; | ||
14 | |||
15 | struct GNUNET_CHAT_Context | ||
16 | { | ||
17 | struct GNUNET_CHAT_Handle *handle; | ||
18 | struct GNUNET_MESSENGER_Room *room; | ||
19 | |||
20 | struct GNUNET_HashCode key; | ||
21 | }; | ||
22 | |||
23 | struct GNUNET_CHAT_Context* | ||
24 | context_create (struct GNUNET_CHAT_Handle *handle, | ||
25 | const struct GNUNET_HashCode *key); | ||
26 | |||
27 | void | ||
28 | context_destroy (struct GNUNET_CHAT_Context* context); | ||
29 | |||
30 | const struct GNUNET_HashCode* | ||
31 | context_get_key (struct GNUNET_CHAT_Context* context); | ||
32 | |||
33 | #endif /* GNUNET_CHAT_CONTEXT_H_ */ | ||
diff --git a/src/gnunet_chat_file.c b/src/gnunet_chat_file.c new file mode 100644 index 0000000..e58066b --- /dev/null +++ b/src/gnunet_chat_file.c | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | * @author Tobias Frisch | ||
3 | * @file gnunet_chat_file.c | ||
4 | */ | ||
5 | |||
6 | #include "gnunet_chat_lib.h" | ||
7 | #include "gnunet_chat_file.h" | ||
8 | |||
9 | void | ||
10 | GNUNET_CHAT_file_start_download (struct GNUNET_CHAT_File *file) | ||
11 | { | ||
12 | if (!file) | ||
13 | return; | ||
14 | |||
15 | struct GNUNET_FS_Handle *handle; | ||
16 | const char *path = ""; // TODO: path = download_directory + filename | ||
17 | |||
18 | GNUNET_FS_download_start( | ||
19 | handle, | ||
20 | file->uri, | ||
21 | NULL, | ||
22 | path, | ||
23 | NULL, | ||
24 | 0, | ||
25 | 0, | ||
26 | 0, | ||
27 | GNUNET_FS_DOWNLOAD_OPTION_NONE, | ||
28 | NULL, | ||
29 | NULL | ||
30 | ); | ||
31 | } | ||
32 | |||
33 | void | ||
34 | GNUNET_CHAT_file_pause_download (struct GNUNET_CHAT_File *file) | ||
35 | { | ||
36 | if (!file) | ||
37 | return; | ||
38 | |||
39 | GNUNET_FS_download_suspend(file->context); | ||
40 | } | ||
41 | |||
42 | void | ||
43 | GNUNET_CHAT_file_resume_download (struct GNUNET_CHAT_File *file) | ||
44 | { | ||
45 | if (!file) | ||
46 | return; | ||
47 | |||
48 | GNUNET_FS_download_resume(file->context); | ||
49 | } | ||
50 | |||
51 | void | ||
52 | GNUNET_CHAT_file_stop_download (struct GNUNET_CHAT_File *file) | ||
53 | { | ||
54 | if (!file) | ||
55 | return; | ||
56 | |||
57 | GNUNET_FS_download_stop(file, GNUNET_YES); | ||
58 | } | ||
diff --git a/src/gnunet_chat_file.h b/src/gnunet_chat_file.h new file mode 100644 index 0000000..5d71aba --- /dev/null +++ b/src/gnunet_chat_file.h | |||
@@ -0,0 +1,19 @@ | |||
1 | /* | ||
2 | * @author Tobias Frisch | ||
3 | * @file gnunet_chat_file.h | ||
4 | */ | ||
5 | |||
6 | #ifndef GNUNET_CHAT_FILE_H_ | ||
7 | #define GNUNET_CHAT_FILE_H_ | ||
8 | |||
9 | #include <gnunet/platform.h> | ||
10 | #include <gnunet/gnunet_fs_service.h> | ||
11 | #include <gnunet/gnunet_util_lib.h> | ||
12 | |||
13 | struct GNUNET_CHAT_File | ||
14 | { | ||
15 | struct GNUNET_FS_Uri* uri; | ||
16 | struct GNUNET_FS_DownloadContext* context; | ||
17 | }; | ||
18 | |||
19 | #endif /* GNUNET_CHAT_FILE_H_ */ | ||
diff --git a/src/gnunet_chat_group.c b/src/gnunet_chat_group.c new file mode 100644 index 0000000..3f9cae0 --- /dev/null +++ b/src/gnunet_chat_group.c | |||
@@ -0,0 +1,179 @@ | |||
1 | /* | ||
2 | * @author Tobias Frisch | ||
3 | * @file gnunet_chat_group.c | ||
4 | */ | ||
5 | |||
6 | #include "gnunet_chat_lib.h" | ||
7 | #include "gnunet_chat_group.h" | ||
8 | #include "gnunet_chat_handle.h" | ||
9 | |||
10 | struct GNUNET_CHAT_Group* | ||
11 | group_create(struct GNUNET_CHAT_Handle *handle) | ||
12 | { | ||
13 | struct GNUNET_CHAT_Group *group = GNUNET_new(struct GNUNET_CHAT_Group); | ||
14 | |||
15 | group->handle = handle; | ||
16 | group->context = context_create(handle, NULL); | ||
17 | group->name = NULL; | ||
18 | |||
19 | if (!group->context) | ||
20 | { | ||
21 | group_destroy (group); | ||
22 | return NULL; | ||
23 | } | ||
24 | |||
25 | const struct GNUNET_HashCode *key = context_get_key(group->context); | ||
26 | |||
27 | const int result = GNUNET_CONTAINER_multihashmap_put( | ||
28 | handle->groups, | ||
29 | key, | ||
30 | group, | ||
31 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST | ||
32 | ); | ||
33 | |||
34 | if (GNUNET_OK != result) { | ||
35 | group_destroy(group); | ||
36 | return NULL; | ||
37 | } | ||
38 | |||
39 | return group; | ||
40 | } | ||
41 | |||
42 | void | ||
43 | group_destroy(struct GNUNET_CHAT_Group* group) | ||
44 | { | ||
45 | if (!group->context) | ||
46 | goto skip_context; | ||
47 | |||
48 | struct GNUNET_CHAT_Handle *handle = group->handle; | ||
49 | const struct GNUNET_HashCode *key = context_get_key(group->context); | ||
50 | |||
51 | GNUNET_CONTAINER_multihashmap_remove( | ||
52 | handle->groups, | ||
53 | key, | ||
54 | group | ||
55 | ); | ||
56 | |||
57 | context_destroy(group->context); | ||
58 | |||
59 | skip_context: | ||
60 | if (group->name) | ||
61 | GNUNET_free(group->name); | ||
62 | |||
63 | GNUNET_free(group); | ||
64 | } | ||
65 | |||
66 | void | ||
67 | GNUNET_CHAT_group_leave (struct GNUNET_CHAT_Group *group) | ||
68 | { | ||
69 | if (!group) | ||
70 | return; | ||
71 | |||
72 | if (group->context) | ||
73 | GNUNET_MESSENGER_close_room(group->context->room); | ||
74 | |||
75 | group_destroy(group); | ||
76 | } | ||
77 | |||
78 | void | ||
79 | GNUNET_CHAT_group_set_name (struct GNUNET_CHAT_Group *group, | ||
80 | const char *name) | ||
81 | { | ||
82 | if (!group) | ||
83 | return; | ||
84 | |||
85 | if (group->name) | ||
86 | GNUNET_free(group->name); | ||
87 | |||
88 | group->name = name? GNUNET_strdup(name) : NULL; | ||
89 | } | ||
90 | |||
91 | const char* | ||
92 | GNUNET_CHAT_group_get_name (const struct GNUNET_CHAT_Group *group) | ||
93 | { | ||
94 | if (!group) | ||
95 | return NULL; | ||
96 | |||
97 | return group->name; | ||
98 | } | ||
99 | |||
100 | void | ||
101 | GNUNET_CHAT_group_invite_contact (struct GNUNET_CHAT_Group *group, | ||
102 | struct GNUNET_CHAT_Contact *contact) | ||
103 | { | ||
104 | if ((!group) || (!contact)) | ||
105 | return; | ||
106 | |||
107 | struct GNUNET_CHAT_Context *context = GNUNET_CHAT_contact_get_context(contact); | ||
108 | |||
109 | if (!context) | ||
110 | return; | ||
111 | |||
112 | struct GNUNET_MESSENGER_Handle *messenger = group->handle->handles.messenger; | ||
113 | GNUNET_MESSENGER_open_room(messenger, context_get_key(group->context)); | ||
114 | |||
115 | struct GNUNET_MESSENGER_Message message; | ||
116 | message.header.kind = GNUNET_MESSENGER_KIND_INVITE; | ||
117 | |||
118 | int result = GNUNET_CRYPTO_get_peer_identity( | ||
119 | group->handle->cfg, | ||
120 | &(message.body.invite.door) | ||
121 | ); | ||
122 | |||
123 | if (GNUNET_OK != result) | ||
124 | return; | ||
125 | |||
126 | GNUNET_memcpy( | ||
127 | &(message.body.invite.key), | ||
128 | context_get_key(group->context), | ||
129 | sizeof(message.body.invite.key) | ||
130 | ); | ||
131 | |||
132 | GNUNET_MESSENGER_send_message(context->room, &message, NULL); | ||
133 | } | ||
134 | |||
135 | struct GNUNET_CHAT_GroupIterateContacts | ||
136 | { | ||
137 | struct GNUNET_CHAT_Group *group; | ||
138 | GNUNET_CHAT_GroupContactCallback callback; | ||
139 | void *cls; | ||
140 | }; | ||
141 | |||
142 | static int | ||
143 | group_iterate_members (void* cls, struct GNUNET_MESSENGER_Room *room, | ||
144 | const struct GNUNET_MESSENGER_Contact *contact) | ||
145 | { | ||
146 | struct GNUNET_CHAT_GroupIterateContacts *iterate = cls; | ||
147 | |||
148 | return iterate->callback(iterate->cls, iterate->group, NULL); // TODO | ||
149 | } | ||
150 | |||
151 | int | ||
152 | GNUNET_CHAT_group_iterate_contacts (struct GNUNET_CHAT_Group *group, | ||
153 | GNUNET_CHAT_GroupContactCallback callback, | ||
154 | void *cls) | ||
155 | { | ||
156 | if (!group) | ||
157 | return GNUNET_SYSERR; | ||
158 | |||
159 | if (!callback) | ||
160 | return GNUNET_MESSENGER_iterate_members(group->context->room, NULL, cls); | ||
161 | |||
162 | struct GNUNET_CHAT_GroupIterateContacts iterate; | ||
163 | iterate.group = group; | ||
164 | iterate.callback = callback; | ||
165 | iterate.cls = cls; | ||
166 | |||
167 | return GNUNET_MESSENGER_iterate_members( | ||
168 | group->context->room, group_iterate_members, &iterate | ||
169 | ); | ||
170 | } | ||
171 | |||
172 | struct GNUNET_CHAT_Context* | ||
173 | GNUNET_CHAT_group_get_context (struct GNUNET_CHAT_Group *group) | ||
174 | { | ||
175 | if (!group) | ||
176 | return NULL; | ||
177 | |||
178 | return group->context; | ||
179 | } | ||
diff --git a/src/gnunet_chat_group.h b/src/gnunet_chat_group.h new file mode 100644 index 0000000..0ea19f5 --- /dev/null +++ b/src/gnunet_chat_group.h | |||
@@ -0,0 +1,25 @@ | |||
1 | /* | ||
2 | * @author Tobias Frisch | ||
3 | * @file gnunet_chat_group.h | ||
4 | */ | ||
5 | |||
6 | #ifndef GNUNET_CHAT_GROUP_H_ | ||
7 | #define GNUNET_CHAT_GROUP_H_ | ||
8 | |||
9 | #include "gnunet_chat_context.h" | ||
10 | |||
11 | struct GNUNET_CHAT_Group | ||
12 | { | ||
13 | struct GNUNET_CHAT_Handle *handle; | ||
14 | struct GNUNET_CHAT_Context *context; | ||
15 | |||
16 | char *name; | ||
17 | }; | ||
18 | |||
19 | struct GNUNET_CHAT_Group* | ||
20 | group_create(struct GNUNET_CHAT_Handle *handle); | ||
21 | |||
22 | void | ||
23 | group_destroy(struct GNUNET_CHAT_Group* group); | ||
24 | |||
25 | #endif /* GNUNET_CHAT_GROUP_H_ */ | ||
diff --git a/src/gnunet_chat_handle.c b/src/gnunet_chat_handle.c new file mode 100644 index 0000000..888dc65 --- /dev/null +++ b/src/gnunet_chat_handle.c | |||
@@ -0,0 +1,170 @@ | |||
1 | /* | ||
2 | * @author Tobias Frisch | ||
3 | * @file gnunet_chat_handle.c | ||
4 | */ | ||
5 | |||
6 | #include "gnunet_chat_lib.h" | ||
7 | #include "gnunet_chat_handle.h" | ||
8 | #include "gnunet_chat_group.h" | ||
9 | |||
10 | static void handle_arm_connection(void* cls, int connected) { | ||
11 | struct GNUNET_CHAT_Handle *handle = cls; | ||
12 | |||
13 | if (GNUNET_YES == connected) { | ||
14 | GNUNET_ARM_request_service_start(handle->handles.arm, "messenger", GNUNET_OS_INHERIT_STD_NONE, NULL, NULL); | ||
15 | GNUNET_ARM_request_service_start(handle->handles.arm, "fs", GNUNET_OS_INHERIT_STD_NONE, NULL, NULL); | ||
16 | } else { | ||
17 | GNUNET_ARM_request_service_start(handle->handles.arm, "arm", GNUNET_OS_INHERIT_STD_NONE, NULL, NULL); | ||
18 | } | ||
19 | } | ||
20 | |||
21 | |||
22 | struct GNUNET_CHAT_Handle* | ||
23 | GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle* cfg, | ||
24 | const char *name) { | ||
25 | if (!cfg) | ||
26 | return NULL; | ||
27 | |||
28 | struct GNUNET_CHAT_Handle *handle = GNUNET_new(struct GNUNET_CHAT_Handle); | ||
29 | memset(handle, 0, sizeof(*handle)); | ||
30 | handle->cfg = cfg; | ||
31 | |||
32 | handle->handles.arm = GNUNET_ARM_connect(cfg, &handle_arm_connection, handle); | ||
33 | |||
34 | if (handle->handles.arm) | ||
35 | handle_arm_connection(handle, GNUNET_NO); | ||
36 | |||
37 | handle->handles.messenger = GNUNET_MESSENGER_connect( | ||
38 | cfg, name, NULL, NULL, NULL, NULL //TODO | ||
39 | ); | ||
40 | |||
41 | if (!handle->handles.messenger) | ||
42 | { | ||
43 | GNUNET_CHAT_stop(handle); | ||
44 | return NULL; | ||
45 | } | ||
46 | |||
47 | handle->handles.fs = GNUNET_FS_start( | ||
48 | cfg, | ||
49 | NULL, //TODO | ||
50 | NULL, | ||
51 | GNUNET_FS_FLAGS_NONE, | ||
52 | GNUNET_FS_OPTIONS_END | ||
53 | ); | ||
54 | |||
55 | handle->contacts = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | ||
56 | handle->groups = GNUNET_CONTAINER_multihashmap_create(8, GNUNET_NO); | ||
57 | |||
58 | return handle; | ||
59 | } | ||
60 | |||
61 | void | ||
62 | GNUNET_CHAT_stop (struct GNUNET_CHAT_Handle *handle) | ||
63 | { | ||
64 | if (!handle) | ||
65 | return; | ||
66 | |||
67 | if (handle->handles.fs) | ||
68 | { | ||
69 | // TODO: stop each action | ||
70 | |||
71 | GNUNET_FS_stop(handle->handles.fs); | ||
72 | handle->handles.fs = NULL; | ||
73 | } | ||
74 | |||
75 | if (handle->handles.messenger) | ||
76 | { | ||
77 | // TODO: stop everything related | ||
78 | |||
79 | GNUNET_MESSENGER_disconnect(handle->handles.messenger); | ||
80 | handle->handles.messenger = NULL; | ||
81 | } | ||
82 | |||
83 | if (handle->groups) | ||
84 | { | ||
85 | // TODO: destroy each | ||
86 | |||
87 | GNUNET_CONTAINER_multihashmap_destroy(handle->groups); | ||
88 | handle->groups = NULL; | ||
89 | } | ||
90 | |||
91 | if (handle->contacts) | ||
92 | { | ||
93 | // TODO: destroy each | ||
94 | |||
95 | GNUNET_CONTAINER_multihashmap_destroy(handle->contacts); | ||
96 | handle->contacts = NULL; | ||
97 | } | ||
98 | |||
99 | if (handle->handles.arm) | ||
100 | { | ||
101 | //TODO: stop started services? | ||
102 | |||
103 | GNUNET_ARM_disconnect(handle->handles.arm); | ||
104 | handle->handles.arm = NULL; | ||
105 | } | ||
106 | |||
107 | GNUNET_free(handle); | ||
108 | } | ||
109 | |||
110 | int | ||
111 | GNUNET_CHAT_update (struct GNUNET_CHAT_Handle *handle) | ||
112 | { | ||
113 | if (!handle) | ||
114 | return GNUNET_SYSERR; | ||
115 | |||
116 | return GNUNET_MESSENGER_update(handle->handles.messenger); | ||
117 | } | ||
118 | |||
119 | int | ||
120 | GNUNET_CHAT_set_name (struct GNUNET_CHAT_Handle *handle, | ||
121 | const char *name) | ||
122 | { | ||
123 | if (!handle) | ||
124 | return GNUNET_SYSERR; | ||
125 | |||
126 | return GNUNET_MESSENGER_set_name(handle, name); | ||
127 | } | ||
128 | |||
129 | const char* | ||
130 | GNUNET_CHAT_get_name (const struct GNUNET_CHAT_Handle *handle) | ||
131 | { | ||
132 | if (!handle) | ||
133 | return GNUNET_SYSERR; | ||
134 | |||
135 | return GNUNET_MESSENGER_get_name(handle->handles.messenger); | ||
136 | } | ||
137 | |||
138 | const struct GNUNET_IDENTITY_PublicKey* | ||
139 | GNUNET_CHAT_get_key (const struct GNUNET_CHAT_Handle *handle) | ||
140 | { | ||
141 | if (!handle) | ||
142 | return GNUNET_SYSERR; | ||
143 | |||
144 | return GNUNET_MESSENGER_get_key(handle->handles.messenger); | ||
145 | } | ||
146 | |||
147 | int | ||
148 | GNUNET_CHAT_iterate_contacts (struct GNUNET_CHAT_Handle *handle, | ||
149 | GNUNET_CHAT_ContactCallback callback, | ||
150 | void *cls) | ||
151 | { | ||
152 | return GNUNET_SYSERR; | ||
153 | } | ||
154 | |||
155 | struct GNUNET_CHAT_Group* | ||
156 | GNUNET_CHAT_group_create (struct GNUNET_CHAT_Handle *handle) | ||
157 | { | ||
158 | if (!handle) | ||
159 | return NULL; | ||
160 | |||
161 | return group_create(handle); | ||
162 | } | ||
163 | |||
164 | int | ||
165 | GNUNET_CHAT_iterate_groups (struct GNUNET_CHAT_Handle *handle, | ||
166 | GNUNET_CHAT_GroupCallback callback, | ||
167 | void *cls) | ||
168 | { | ||
169 | return GNUNET_SYSERR; | ||
170 | } | ||
diff --git a/src/gnunet_chat_handle.h b/src/gnunet_chat_handle.h new file mode 100644 index 0000000..8c50021 --- /dev/null +++ b/src/gnunet_chat_handle.h | |||
@@ -0,0 +1,33 @@ | |||
1 | /* | ||
2 | * @author Tobias Frisch | ||
3 | * @file gnunet_chat_handle.h | ||
4 | */ | ||
5 | |||
6 | #ifndef GNUNET_CHAT_HANDLE_H_ | ||
7 | #define GNUNET_CHAT_HANDLE_H_ | ||
8 | |||
9 | #include <gnunet/platform.h> | ||
10 | #include <gnunet/gnunet_config.h> | ||
11 | #include <gnunet/gnunet_container_lib.h> | ||
12 | #include <gnunet/gnunet_arm_service.h> | ||
13 | #include <gnunet/gnunet_fs_service.h> | ||
14 | #include <gnunet/gnunet_identity_service.h> | ||
15 | #include <gnunet/gnunet_messenger_service.h> | ||
16 | #include <gnunet/gnunet_regex_service.h> | ||
17 | #include <gnunet/gnunet_util_lib.h> | ||
18 | |||
19 | struct GNUNET_CHAT_Handle | ||
20 | { | ||
21 | const struct GNUNET_CONFIGURATION_Handle* cfg; | ||
22 | |||
23 | struct { | ||
24 | struct GNUNET_ARM_Handle* arm; | ||
25 | struct GNUNET_FS_Handle* fs; | ||
26 | struct GNUNET_MESSENGER_Handle* messenger; | ||
27 | } handles; | ||
28 | |||
29 | struct GNUNET_CONTAINER_MultiHashMap *contacts; | ||
30 | struct GNUNET_CONTAINER_MultiHashMap *groups; | ||
31 | }; | ||
32 | |||
33 | #endif /* GNUNET_CHAT_HANDLE_H_ */ | ||
diff --git a/src/gnunet_chat_message.c b/src/gnunet_chat_message.c new file mode 100644 index 0000000..bceef77 --- /dev/null +++ b/src/gnunet_chat_message.c | |||
@@ -0,0 +1,64 @@ | |||
1 | /* | ||
2 | * @author Tobias Frisch | ||
3 | * @file gnunet_chat_message.c | ||
4 | */ | ||
5 | |||
6 | #include "gnunet_chat_lib.h" | ||
7 | #include "gnunet_chat_message.h" | ||
8 | |||
9 | enum GNUNET_CHAT_MessageKind | ||
10 | GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message) | ||
11 | { | ||
12 | if (!message) | ||
13 | return GNUNET_CHAT_KIND_UNKNOWN; | ||
14 | |||
15 | switch (message->message->header.kind) { | ||
16 | case GNUNET_MESSENGER_KIND_TEXT: | ||
17 | return GNUNET_CHAT_KIND_TEXT; | ||
18 | case GNUNET_MESSENGER_KIND_FILE: | ||
19 | return GNUNET_CHAT_KIND_FILE; | ||
20 | default: | ||
21 | return GNUNET_CHAT_KIND_UNKNOWN; | ||
22 | } | ||
23 | } | ||
24 | |||
25 | struct GNUNET_TIME_Absolute | ||
26 | GNUNET_CHAT_message_get_timestamp (const struct GNUNET_CHAT_Message *message) | ||
27 | { | ||
28 | if (!message) | ||
29 | return GNUNET_TIME_absolute_get_zero_(); | ||
30 | |||
31 | return GNUNET_TIME_absolute_ntoh(message->message->header.timestamp); | ||
32 | } | ||
33 | |||
34 | const struct GNUNET_CHAT_Contact* | ||
35 | GNUNET_CHAT_message_get_sender (const struct GNUNET_CHAT_Message *message) | ||
36 | { | ||
37 | return NULL; | ||
38 | } | ||
39 | |||
40 | int | ||
41 | GNUNET_CHAT_message_get_read_receipt (const struct GNUNET_CHAT_Message *message, | ||
42 | GNUNET_CHAT_MessageReadReceiptCallback callback, | ||
43 | void *cls) | ||
44 | { | ||
45 | return GNUNET_SYSERR; | ||
46 | } | ||
47 | |||
48 | const char* | ||
49 | GNUNET_CHAT_message_get_text (const struct GNUNET_CHAT_Message *message) | ||
50 | { | ||
51 | if (!message) | ||
52 | return NULL; | ||
53 | |||
54 | if (GNUNET_MESSENGER_KIND_TEXT != message->message->header.kind) | ||
55 | return NULL; | ||
56 | |||
57 | return message->message->body.text.text; | ||
58 | } | ||
59 | |||
60 | struct GNUNET_CHAT_File* | ||
61 | GNUNET_CHAT_message_get_file (const struct GNUNET_CHAT_Message *message) | ||
62 | { | ||
63 | return NULL; | ||
64 | } | ||
diff --git a/src/gnunet_chat_message.h b/src/gnunet_chat_message.h new file mode 100644 index 0000000..df3446f --- /dev/null +++ b/src/gnunet_chat_message.h | |||
@@ -0,0 +1,18 @@ | |||
1 | /* | ||
2 | * @author Tobias Frisch | ||
3 | * @file gnunet_chat_message.h | ||
4 | */ | ||
5 | |||
6 | #ifndef GNUNET_CHAT_MESSAGE_H_ | ||
7 | #define GNUNET_CHAT_MESSAGE_H_ | ||
8 | |||
9 | #include <gnunet/platform.h> | ||
10 | #include <gnunet/gnunet_messenger_service.h> | ||
11 | #include <gnunet/gnunet_util_lib.h> | ||
12 | |||
13 | struct GNUNET_CHAT_Message | ||
14 | { | ||
15 | struct GNUNET_MESSENGER_Message *message; | ||
16 | }; | ||
17 | |||
18 | #endif /* GNUNET_CHAT_MESSAGE_H_ */ | ||