diff options
Diffstat (limited to 'src/gnunet_chat_account.c')
-rw-r--r-- | src/gnunet_chat_account.c | 68 |
1 files changed, 64 insertions, 4 deletions
diff --git a/src/gnunet_chat_account.c b/src/gnunet_chat_account.c index 95418cc..016128b 100644 --- a/src/gnunet_chat_account.c +++ b/src/gnunet_chat_account.c | |||
@@ -23,17 +23,21 @@ | |||
23 | */ | 23 | */ |
24 | 24 | ||
25 | #include "gnunet_chat_account.h" | 25 | #include "gnunet_chat_account.h" |
26 | #include "gnunet_chat_handle.h" | ||
26 | #include "gnunet_chat_util.h" | 27 | #include "gnunet_chat_util.h" |
27 | 28 | ||
29 | #include <gnunet/gnunet_common.h> | ||
30 | #include <gnunet/gnunet_identity_service.h> | ||
31 | #include <gnunet/gnunet_messenger_service.h> | ||
32 | |||
28 | struct GNUNET_CHAT_Account* | 33 | struct GNUNET_CHAT_Account* |
29 | account_create_from_ego(struct GNUNET_IDENTITY_Ego *ego, | 34 | account_create(const char *name) |
30 | const char *name) | ||
31 | { | 35 | { |
32 | GNUNET_assert((ego) && (name)); | 36 | GNUNET_assert(name); |
33 | 37 | ||
34 | struct GNUNET_CHAT_Account *account = GNUNET_new(struct GNUNET_CHAT_Account); | 38 | struct GNUNET_CHAT_Account *account = GNUNET_new(struct GNUNET_CHAT_Account); |
35 | 39 | ||
36 | account->ego = ego; | 40 | account->ego = NULL; |
37 | account->directory = NULL; | 41 | account->directory = NULL; |
38 | account->name = NULL; | 42 | account->name = NULL; |
39 | 43 | ||
@@ -44,6 +48,19 @@ account_create_from_ego(struct GNUNET_IDENTITY_Ego *ego, | |||
44 | return account; | 48 | return account; |
45 | } | 49 | } |
46 | 50 | ||
51 | struct GNUNET_CHAT_Account* | ||
52 | account_create_from_ego(struct GNUNET_IDENTITY_Ego *ego, | ||
53 | const char *name) | ||
54 | { | ||
55 | GNUNET_assert((ego) && (name)); | ||
56 | |||
57 | struct GNUNET_CHAT_Account *account = account_create(name); | ||
58 | |||
59 | account->ego = ego; | ||
60 | |||
61 | return account; | ||
62 | } | ||
63 | |||
47 | void | 64 | void |
48 | account_update_directory (struct GNUNET_CHAT_Account *account, | 65 | account_update_directory (struct GNUNET_CHAT_Account *account, |
49 | const char *base_directory) | 66 | const char *base_directory) |
@@ -53,6 +70,12 @@ account_update_directory (struct GNUNET_CHAT_Account *account, | |||
53 | if (account->directory) | 70 | if (account->directory) |
54 | GNUNET_free(account->directory); | 71 | GNUNET_free(account->directory); |
55 | 72 | ||
73 | if (!(account->ego)) | ||
74 | { | ||
75 | account->directory = NULL; | ||
76 | return; | ||
77 | } | ||
78 | |||
56 | struct GNUNET_CRYPTO_PublicKey key; | 79 | struct GNUNET_CRYPTO_PublicKey key; |
57 | GNUNET_IDENTITY_ego_get_public_key(account->ego, &key); | 80 | GNUNET_IDENTITY_ego_get_public_key(account->ego, &key); |
58 | 81 | ||
@@ -82,6 +105,43 @@ account_get_key (const struct GNUNET_CHAT_Account *account) | |||
82 | } | 105 | } |
83 | 106 | ||
84 | void | 107 | void |
108 | account_update_ego(struct GNUNET_CHAT_Account *account, | ||
109 | struct GNUNET_CHAT_Handle *handle, | ||
110 | struct GNUNET_IDENTITY_Ego *ego) | ||
111 | { | ||
112 | GNUNET_assert((account) && (handle) && (ego) && (account->ego != ego)); | ||
113 | |||
114 | enum GNUNET_CHAT_MessageFlag flag; | ||
115 | if ((!(account->ego)) && (handle->current != account)) | ||
116 | flag = GNUNET_CHAT_FLAG_CREATE_ACCOUNT; | ||
117 | else | ||
118 | flag = GNUNET_CHAT_FLAG_UPDATE_ACCOUNT; | ||
119 | |||
120 | account->ego = ego; | ||
121 | |||
122 | if (handle->directory) | ||
123 | account_update_directory(account, handle->directory); | ||
124 | |||
125 | if ((handle->current == account) && (handle->messenger)) | ||
126 | { | ||
127 | GNUNET_MESSENGER_set_key( | ||
128 | handle->messenger, | ||
129 | GNUNET_IDENTITY_ego_get_private_key(account->ego) | ||
130 | ); | ||
131 | |||
132 | handle_update_key(handle); | ||
133 | } | ||
134 | |||
135 | handle_send_internal_message( | ||
136 | handle, | ||
137 | account, | ||
138 | NULL, | ||
139 | flag, | ||
140 | NULL | ||
141 | ); | ||
142 | } | ||
143 | |||
144 | void | ||
85 | account_destroy(struct GNUNET_CHAT_Account *account) | 145 | account_destroy(struct GNUNET_CHAT_Account *account) |
86 | { | 146 | { |
87 | GNUNET_assert(account); | 147 | GNUNET_assert(account); |