aboutsummaryrefslogtreecommitdiff
path: root/src/plugins/chat/chat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/plugins/chat/chat.c')
-rw-r--r--src/plugins/chat/chat.c204
1 files changed, 200 insertions, 4 deletions
diff --git a/src/plugins/chat/chat.c b/src/plugins/chat/chat.c
index 91be97ad..de607f7f 100644
--- a/src/plugins/chat/chat.c
+++ b/src/plugins/chat/chat.c
@@ -24,20 +24,216 @@
24 * @author Igor Wronsky 24 * @author Igor Wronsky
25 * @author Nathan Evans 25 * @author Nathan Evans
26 * 26 *
27 * This file contains the about dialog.
28 */ 27 */
29 28
30#include "platform.h" 29#include "chat.h"
31#include "gnunetgtk_common.h" 30
31const GNUNET_RSA_PublicKey pub_key;
32const struct GNUNET_RSA_PrivateKey *priv_key;
33
34/**
35 * A message was sent in the chat to us.
36 *
37 * @param timestamp when was the message sent?
38 * @param senderNick what is the nickname of the sender? (maybe NULL)
39 * @param message the message (maybe NULL, especially if confirmation
40 * is requested before delivery; the protocol will ensure
41 * that this function is called again with the full message
42 * if a confirmation is transmitted; if the message is NULL,
43 * the user is merely asked if engaging in the exchange is ok
44 * @param room in which room was the message received?
45 * @param options options for the message
46 * @return GNUNET_OK to accept the message now, GNUNET_NO to
47 * accept (but user is away), GNUNET_SYSERR to signal denied delivery
48 */
49static int
50receive_callback (void *cls,
51 struct GNUNET_CHAT_Room *room,
52 const char *senderNick,
53 const char *message,
54 GNUNET_CronTime timestamp, GNUNET_CHAT_MSG_OPTIONS options)
55{
56 fprintf (stdout, "%s: %s\n", senderNick, message);
57 return GNUNET_OK;
58}
32 59
33void 60void
34init_chat () 61init_chat ()
35{ 62{
36 GtkWidget *tab; 63 GtkWidget *tab;
37 64 GtkWidget *button;
65 GtkWidget *hbox;
66
67 priv_key = GNUNET_RSA_create_key ();
68 GNUNET_RSA_get_public_key (priv_key, &pub_key);
69
70 g_print("g_print works!\n");
71 hbox =
72 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "chatHBox");
73
74
38 tab = 75 tab =
39 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "chatnotebookvbox"); 76 glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "chatnotebookvbox");
77
78 button = gtk_button_new_with_label("hello world");
79
80 gtk_container_add(GTK_CONTAINER(tab), button);
81
40 gtk_widget_show (tab); 82 gtk_widget_show (tab);
41} 83}
42 84
85void
86on_chat_room_name_key_press_event_chat (GtkWidget *widget, GdkEventKey *event, gpointer func_data)
87{
88 g_print("Key pressed....\n");
89}
90
91void
92on_chat_room_name_button_click_event_chat(GtkWidget* widget, gpointer data)
93{
94 GtkEntry *room_entry;
95 GtkEntry *nick_entry;
96 char *room_text;
97 char *nick_text;
98
99 room_entry = GTK_ENTRY(glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "chatRoomNameEntry"));
100 nick_entry = GTK_ENTRY(glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "chatRoomMonikerEntry"));
101
102 room_text = (char*)gtk_entry_get_text (room_entry);
103 nick_text = (char*)gtk_entry_get_text (nick_entry);
104
105 create_chat_room_tab(room_text,nick_text);
106}
107
108int
109create_chat_room_tab(char *room_name,char *nick)
110{
111 GladeXML *chatXML;
112 GtkWidget *newChatWindow;
113 GtkWidget *chatnotebook;
114 GtkWidget *chatLabel;
115
116 chatnotebook = glade_xml_get_widget (GNUNET_GTK_get_main_glade_XML (), "chatnotebook");
117 chatXML = glade_xml_new (GNUNET_GTK_get_glade_filename (), "chatFrame",PACKAGE_NAME);
118 GNUNET_GTK_connect_glade_with_plugins (chatXML);
119 newChatWindow = extractMainWidgetFromWindow (chatXML, "chatFrame");
120
121 chatLabel = gtk_label_new(room_name);
122 gtk_notebook_insert_page (GTK_NOTEBOOK(chatnotebook),newChatWindow,chatLabel,1);
123
124 gtk_widget_show (chatnotebook);
125
126 GNUNET_CHAT_gui_join_room (nick,room_name,&pub_key,priv_key,&receive_callback,NULL);
127 return 1;
128}
129
130int
131remove_chat_room_tab(char *room_name)
132{
133
134 return -1;
135}
136
137/**
138 * Join a chat room.
139 *
140 * @param nickname the nick you want to use
141 * @param memberInfo public information about you
142 * @param callback which function to call if a message has
143 * been received?
144 * @param cls argument to callback
145 * @return NULL on error
146 */
147struct GNUNET_CHAT_Room *
148GNUNET_CHAT_gui_join_room (const char *nickname,
149 const char *room_name,
150 const GNUNET_RSA_PublicKey * me,
151 const struct GNUNET_RSA_PrivateKey *key,
152 GNUNET_CHAT_MessageCallback callback, void *cls)
153{
154#if 0
155 CS_chat_JOIN_MESSAGE *join_msg;
156 GNUNET_MessageHeader csHdr;
157
158 GNUNET_HashCode hash_of_me;
159 GNUNET_HashCode hash_of_room_name;
160
161 struct GNUNET_CHAT_Room *chat_room;
162 struct GNUNET_ClientServerConnection *sock;
163
164 int size_of_join;
165
166 csHdr.size = htons (sizeof (CS_chat_JOIN_MESSAGE));
167 csHdr.type = htons (GNUNET_CS_PROTO_CHAT_JOIN_MSG);
168
169 sock = GNUNET_client_connection_create (ectx, cfg);
170
171 if (sock == NULL)
172 {
173 fprintf (stderr, _("Error establishing connection with gnunetd.\n"));
174 return NULL;
175 }
176
177 // connect
178 GNUNET_hash (me, sizeof (GNUNET_RSA_PublicKey), &hash_of_me);
179 GNUNET_hash (room_name, strlen (room_name), &hash_of_room_name);
180
181 size_of_join =
182 sizeof (CS_chat_JOIN_MESSAGE) + strlen (nickname) +
183 sizeof (GNUNET_RSA_PublicKey) + strlen (room_name);
184 join_msg = GNUNET_malloc (size_of_join);
185
186 join_msg->nick_len = htons (strlen (nickname));
187 join_msg->pubkey_len = htons (sizeof (GNUNET_RSA_PublicKey));
188 //join_msg->room_name_len = htonl (strlen (room_name));
189
190
191 memcpy (&join_msg->nick[0], nickname, strlen (nickname));
192 memcpy (&join_msg->nick[strlen (nickname)], me,
193 sizeof (GNUNET_RSA_PublicKey));
194 memcpy (&join_msg->nick[strlen (nickname) + sizeof (GNUNET_RSA_PublicKey)],
195 room_name, strlen (room_name));
196
197 join_msg->header = csHdr;
198 join_msg->header.size = htons (size_of_join);
199
200 if (GNUNET_SYSERR ==
201 GNUNET_client_connection_write (sock, &join_msg->header))
202 {
203 /* ALREADY LOGGED */
204 fprintf (stderr, _("Error writing to socket.\n"));
205 GNUNET_free (join_msg);
206 return NULL;
207 }
208
209 GNUNET_free (join_msg);
210
211 // allocate & init room struct
212 chat_room = GNUNET_malloc (sizeof (struct GNUNET_CHAT_Room));
213 chat_room->nickname = GNUNET_malloc (strlen (nickname) + 1);
214 strncpy (chat_room->nickname, nickname, strlen (nickname) + 1);
215
216 chat_room->room_name = GNUNET_malloc (strlen (room_name) + 1);
217 strncpy (chat_room->room_name, room_name, strlen (room_name) + 1);
218
219 chat_room->room_name_hash = hash_of_room_name;
220 chat_room->my_public_key = me;
221 chat_room->my_public_key_hash = hash_of_me;
222 chat_room->my_private_key = key;
223 chat_room->callback = callback;
224 chat_room->callback_cls = cls;
225 chat_room->ectx = ectx;
226 chat_room->cfg = cfg;
227 chat_room->memberInfo = GNUNET_malloc (strlen (memberInfo) + 1);
228 strncpy (chat_room->memberInfo, memberInfo, strlen (memberInfo) + 1);
229 chat_room->sock = sock;
230
231 // create pthread
232 chat_room->listen_thread =
233 GNUNET_thread_create (&poll_thread, chat_room, 1024 * 2);
234
235 return chat_room;
236#endif
237}
238
43/* end of chat.c */ 239/* end of chat.c */