aboutsummaryrefslogtreecommitdiff
path: root/src/gnunet_chat_lib.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gnunet_chat_lib.c')
-rw-r--r--src/gnunet_chat_lib.c76
1 files changed, 71 insertions, 5 deletions
diff --git a/src/gnunet_chat_lib.c b/src/gnunet_chat_lib.c
index be07f85..e40ef0c 100644
--- a/src/gnunet_chat_lib.c
+++ b/src/gnunet_chat_lib.c
@@ -40,14 +40,13 @@
40struct GNUNET_CHAT_Handle* 40struct GNUNET_CHAT_Handle*
41GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg, 41GNUNET_CHAT_start (const struct GNUNET_CONFIGURATION_Handle *cfg,
42 const char *directory, 42 const char *directory,
43 const char *name,
44 GNUNET_CHAT_ContextMessageCallback msg_cb, void *msg_cls) 43 GNUNET_CHAT_ContextMessageCallback msg_cb, void *msg_cls)
45{ 44{
46 if (!cfg) 45 if (!cfg)
47 return NULL; 46 return NULL;
48 47
49 return handle_create_from_config( 48 return handle_create_from_config(
50 cfg, directory, name, 49 cfg, directory,
51 msg_cb, msg_cls 50 msg_cb, msg_cls
52 ); 51 );
53} 52}
@@ -64,6 +63,71 @@ GNUNET_CHAT_stop (struct GNUNET_CHAT_Handle *handle)
64 63
65 64
66int 65int
66GNUNET_CHAT_iterate_accounts(const struct GNUNET_CHAT_Handle *handle,
67 GNUNET_CHAT_AccountCallback callback,
68 void *cls)
69{
70 if (!handle)
71 return GNUNET_SYSERR;
72
73 int result = 0;
74
75 struct GNUNET_CHAT_InternalAccounts *accounts = handle->accounts_head;
76 while (accounts)
77 {
78 if (!(accounts->account))
79 return GNUNET_SYSERR;
80
81 result++;
82
83 if ((!callback) && (GNUNET_YES != callback(cls, handle, accounts->account)))
84 break;
85
86 accounts = accounts->next;
87 }
88
89 return result;
90}
91
92
93void
94GNUNET_CHAT_connect (struct GNUNET_CHAT_Handle *handle,
95 const struct GNUNET_CHAT_Account *account)
96{
97 if (!handle)
98 return;
99
100 if (handle->current)
101 handle_disconnect(handle);
102
103 if (!account)
104 return;
105
106 handle_connect(handle, account);
107}
108
109
110void
111GNUNET_CHAT_disconnect (struct GNUNET_CHAT_Handle *handle)
112{
113 if ((!handle) || (!(handle->current)))
114 return;
115
116 handle_disconnect(handle);
117}
118
119
120const struct GNUNET_CHAT_Account*
121GNUNET_CHAT_get_connected(const struct GNUNET_CHAT_Handle *handle)
122{
123 if (!handle)
124 return NULL;
125
126 return handle->current;
127}
128
129
130int
67GNUNET_CHAT_update (struct GNUNET_CHAT_Handle *handle) 131GNUNET_CHAT_update (struct GNUNET_CHAT_Handle *handle)
68{ 132{
69 if (!handle) 133 if (!handle)
@@ -133,7 +197,7 @@ GNUNET_CHAT_iterate_contacts (struct GNUNET_CHAT_Handle *handle,
133 GNUNET_CHAT_ContactCallback callback, 197 GNUNET_CHAT_ContactCallback callback,
134 void *cls) 198 void *cls)
135{ 199{
136 if (!handle) 200 if ((!handle) || (!(handle->contacts)))
137 return GNUNET_SYSERR; 201 return GNUNET_SYSERR;
138 202
139 struct GNUNET_CHAT_HandleIterateContacts it; 203 struct GNUNET_CHAT_HandleIterateContacts it;
@@ -151,7 +215,7 @@ struct GNUNET_CHAT_Group *
151GNUNET_CHAT_group_create (struct GNUNET_CHAT_Handle *handle, 215GNUNET_CHAT_group_create (struct GNUNET_CHAT_Handle *handle,
152 const char* topic) 216 const char* topic)
153{ 217{
154 if (!handle) 218 if ((!handle) || (!(handle->groups)) || (!(handle->contexts)))
155 return NULL; 219 return NULL;
156 220
157 struct GNUNET_HashCode key; 221 struct GNUNET_HashCode key;
@@ -210,7 +274,7 @@ GNUNET_CHAT_iterate_groups (struct GNUNET_CHAT_Handle *handle,
210 GNUNET_CHAT_GroupCallback callback, 274 GNUNET_CHAT_GroupCallback callback,
211 void *cls) 275 void *cls)
212{ 276{
213 if (!handle) 277 if ((!handle) || (!(handle->groups)))
214 return GNUNET_SYSERR; 278 return GNUNET_SYSERR;
215 279
216 struct GNUNET_CHAT_HandleIterateGroups it; 280 struct GNUNET_CHAT_HandleIterateGroups it;
@@ -784,6 +848,8 @@ GNUNET_CHAT_message_get_kind (const struct GNUNET_CHAT_Message *message)
784 { 848 {
785 case GNUNET_CHAT_FLAG_WARNING: 849 case GNUNET_CHAT_FLAG_WARNING:
786 return GNUNET_CHAT_KIND_WARNING; 850 return GNUNET_CHAT_KIND_WARNING;
851 case GNUNET_CHAT_FLAG_REFRESH:
852 return GNUNET_CHAT_KIND_REFRESH;
787 case GNUNET_CHAT_FLAG_LOGIN: 853 case GNUNET_CHAT_FLAG_LOGIN:
788 return GNUNET_CHAT_KIND_LOGIN; 854 return GNUNET_CHAT_KIND_LOGIN;
789 case GNUNET_CHAT_FLAG_UPDATE: 855 case GNUNET_CHAT_FLAG_UPDATE: