gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r6945 - in GNUnet/src/applications/chat: . lib module tools


From: gnunet
Subject: [GNUnet-SVN] r6945 - in GNUnet/src/applications/chat: . lib module tools
Date: Sat, 31 May 2008 13:28:26 -0600 (MDT)

Author: grothoff
Date: 2008-05-31 13:28:26 -0600 (Sat, 31 May 2008)
New Revision: 6945

Added:
   GNUnet/src/applications/chat/lib/check.conf
   GNUnet/src/applications/chat/lib/loopback_test.c
   GNUnet/src/applications/chat/lib/messaging.c
   GNUnet/src/applications/chat/module/chat.c
   GNUnet/src/applications/chat/module/p2p.c
   GNUnet/src/applications/chat/module/p2p.h
   GNUnet/src/applications/chat/tools/gnunet-chat.c
Removed:
   GNUnet/src/applications/chat/chat.c
   GNUnet/src/applications/chat/chat_p2p.c
   GNUnet/src/applications/chat/chat_p2p.h
   GNUnet/src/applications/chat/chattest.c
   GNUnet/src/applications/chat/check.conf
   GNUnet/src/applications/chat/clientapi.c
   GNUnet/src/applications/chat/gnunet-chat.c
Modified:
   GNUnet/src/applications/chat/Makefile.am
   GNUnet/src/applications/chat/chat.h
   GNUnet/src/applications/chat/lib/Makefile.am
   GNUnet/src/applications/chat/module/Makefile.am
   GNUnet/src/applications/chat/tools/Makefile.am
Log:
moving stuff around

Modified: GNUnet/src/applications/chat/Makefile.am
===================================================================
--- GNUnet/src/applications/chat/Makefile.am    2008-05-31 19:24:20 UTC (rev 
6944)
+++ GNUnet/src/applications/chat/Makefile.am    2008-05-31 19:28:26 UTC (rev 
6945)
@@ -1,48 +1 @@
-INCLUDES = -I$(top_srcdir)/src/include
-
-LDADD = \
- $(top_builddir)/src/util/libgnunetutil.la 
-
-plugindir = $(libdir)/GNUnet
-
-plugin_LTLIBRARIES = \
-  libgnunetmodule_chat.la
-
-lib_LTLIBRARIES = \
-  libgnunetchat_api.la
-
-bin_PROGRAMS = \
- gnunet-chat
-
-gnunet_chat_SOURCES = \
- gnunet-chat.c         
-gnunet_chat_LDADD = \
-  $(top_builddir)/src/applications/chat/libgnunetchat_api.la 
-
-libgnunetchat_api_la_SOURCES = \
-  clientapi.c 
-libgnunetchat_api_la_LIBADD = \
-  $(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
-  $(top_builddir)/src/util/libgnunetutil.la 
-
-libgnunetmodule_chat_la_SOURCES = \
-  chat.c chat.h
-libgnunetmodule_chat_la_LIBADD = \
-  $(top_builddir)/src/util/libgnunetutil.la
-libgnunetmodule_chat_la_LDFLAGS = \
-  -export-dynamic -avoid-version -module
-
-
-
-check_PROGRAMS = \
-  chattest
-
-TESTS = $(check_PROGRAMS)
-
-chattest_SOURCES = \
-  chattest.c 
-chattest_LDADD = \
-  $(top_builddir)/src/applications/testing/libgnunettesting_api.la \
-  $(top_builddir)/src/applications/stats/libgnunetstats_api.la \
-  $(top_builddir)/src/applications/chat/libgnunetchat_api.la \
-  $(top_builddir)/src/util/libgnunetutil.la 
+SUBDIRS = module lib tools .

Deleted: GNUnet/src/applications/chat/chat.c
===================================================================
--- GNUnet/src/applications/chat/chat.c 2008-05-31 19:24:20 UTC (rev 6944)
+++ GNUnet/src/applications/chat/chat.c 2008-05-31 19:28:26 UTC (rev 6945)
@@ -1,316 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2008 Christian Grothoff (and other contributing authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * CHAT CORE. This is the code that is plugged
- * into the GNUnet core to enable chatting.
- *
- * @author Christian Grothoff
- * @author Nathan Evans
- * @file applications/chat/chat.c
- */
-
-#include "platform.h"
-#include "gnunet_protocols.h"
-#include "gnunet_util.h"
-#include "gnunet_core.h"
-#include "chat.h"
-
-/**
- * Linked list of our current clients.
- */
-struct GNUNET_CS_chat_client
-{
-  struct GNUNET_CS_chat_client *next;
-
-  struct GNUNET_ClientHandle *client;
-
-  struct GNUNET_RSA_PrivateKey *private_key;
-
-  char *room;
-
-  /**
-   * Hash of the public key (for convenience).
-   */
-  GNUNET_HashCode id;
-
-  unsigned int msg_options;
-
-};
-
-static struct GNUNET_CS_chat_client *client_list_head;
-
-static GNUNET_CoreAPIForPlugins *coreAPI;
-
-static struct GNUNET_Mutex *chatMutex;
-
-static int
-csHandleTransmitRequest (struct GNUNET_ClientHandle *client,
-                         const GNUNET_MessageHeader * message)
-{
-  static GNUNET_HashCode all_zeros;
-  const CS_chat_MESSAGE_TransmitRequest *cmsg;
-  CS_chat_MESSAGE_ReceiveNotification *rmsg;
-  CS_chat_MESSAGE_ConfirmationReceipt receipt;
-  struct GNUNET_CS_chat_client *pos;
-  const char *room;
-  unsigned int msg_len;
-  int priv_msg;
-
-  if (ntohs (message->size) < sizeof (CS_chat_MESSAGE_TransmitRequest))
-    {
-      GNUNET_GE_BREAK (NULL, 0);
-      return GNUNET_SYSERR;     /* invalid message */
-    }
-  cmsg = (const CS_chat_MESSAGE_TransmitRequest *) message;
-  msg_len = ntohs (message->size) - sizeof (CS_chat_MESSAGE_TransmitRequest);
-  rmsg = GNUNET_malloc (sizeof (CS_chat_MESSAGE_ReceiveNotification) +
-                        msg_len);
-  rmsg->header.size = htons (sizeof (CS_chat_MESSAGE_ReceiveNotification) +
-                             msg_len);
-  rmsg->header.type = htons (GNUNET_CS_PROTO_CHAT_MESSAGE_NOTIFICATION);
-  rmsg->msg_options = cmsg->msg_options;
-  GNUNET_mutex_lock (chatMutex);
-
-  pos = client_list_head;
-  while ((pos != NULL) && (pos->client != client))
-    pos = pos->next;
-  if (pos == NULL)
-    {
-      GNUNET_mutex_unlock (chatMutex);
-      GNUNET_GE_BREAK (NULL, 0);
-      GNUNET_free (rmsg);
-      return GNUNET_SYSERR;     /* not member of chat room! */
-    }
-  room = pos->room;
-  if ((ntohl (cmsg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS) == 0)
-    rmsg->sender = pos->id;
-  else
-    memset (&rmsg->sender, 0, sizeof (GNUNET_HashCode));
-  priv_msg = (0 == memcmp(&all_zeros,
-                         &cmsg->target,
-                         sizeof(GNUNET_HashCode)));
-  memcpy(&rmsg[1],
-        &cmsg[1],
-        msg_len);
-  pos = client_list_head;
-  while (pos != NULL)
-    {
-      if (0 == strcmp (room, pos->room))
-        {
-         if ( ( (!priv_msg) ||
-                (0 == memcmp(&cmsg->target,
-                             &pos->id,
-                             sizeof(GNUNET_HashCode))) ) &&
-              ( (0 == ntohl(cmsg->msg_options)) & (~pos->msg_options) ) )
-           {
-             coreAPI->cs_send_message (pos->client, &rmsg->header, GNUNET_YES);
-             if (0 != (ntohl(cmsg->msg_options)&GNUNET_CHAT_MSG_ACKNOWLEDGED))
-               {
-                 receipt.header.size = 
htons(sizeof(CS_chat_MESSAGE_ConfirmationReceipt));
-                 receipt.header.type = 
htons(GNUNET_CS_PROTO_CHAT_CONFIRMATION_RECEIPT);
-                 receipt.sequence_number = cmsg->sequence_number;
-                 receipt.timestamp = GNUNET_htonll(GNUNET_get_time());
-                 receipt.target = pos->id;
-                 /* FIXME: this will currently *always* be the plaintext 
message;
-                    once we have P2P, we want to sign the encrypted message
-                    (which we currently do not even generate!) */
-                 GNUNET_hash(&cmsg[1],
-                             msg_len,
-                             &receipt.content);
-                 GNUNET_RSA_sign(pos->private_key,
-                                 sizeof(CS_chat_MESSAGE_ConfirmationReceipt) - 
sizeof(GNUNET_RSA_Signature),
-                                 &receipt,
-                                 &receipt.signature);            
-                 coreAPI->cs_send_message (client, &receipt.header, 
GNUNET_YES);
-               }
-           }
-        }
-      pos = pos->next;
-    }
-  GNUNET_mutex_unlock (chatMutex);
-  GNUNET_free (rmsg);
-  return GNUNET_OK;
-}
-
-static int
-csHandleChatJoinRequest (struct GNUNET_ClientHandle *client,
-                         const GNUNET_MessageHeader * message)
-{
-  const CS_chat_MESSAGE_JoinRequest *cmsg;
-  char *room_name;
-  const char *roomptr;
-  unsigned int header_size;
-  unsigned int meta_len;
-  unsigned int room_name_len;
-  struct GNUNET_CS_chat_client *entry;
-  GNUNET_RSA_PublicKey pkey;
-  CS_chat_MESSAGE_JoinNotification *nmsg;
-
-  if (ntohs (message->size) < sizeof (CS_chat_MESSAGE_JoinRequest))
-    {
-      GNUNET_GE_BREAK (NULL, 0);
-      return GNUNET_SYSERR;     /* invalid message */
-    }
-  cmsg = (const CS_chat_MESSAGE_JoinRequest *) message;
-  header_size = ntohs (cmsg->header.size);
-  room_name_len = ntohs (cmsg->room_name_len);
-  if (header_size - sizeof (CS_chat_MESSAGE_JoinRequest) <= room_name_len)
-    {
-      GNUNET_GE_BREAK (NULL, 0);
-      return GNUNET_SYSERR;
-    }
-  meta_len =
-    header_size - sizeof (CS_chat_MESSAGE_JoinRequest) - room_name_len;
-
-  roomptr = (const char *) &cmsg[1];
-  room_name = GNUNET_malloc (room_name_len + 1);
-  memcpy (room_name, roomptr, room_name_len);
-  room_name[room_name_len] = '\0';
-
-  entry = GNUNET_malloc (sizeof (struct GNUNET_CS_chat_client));
-  memset (entry, 0, sizeof (struct GNUNET_CS_chat_client));
-  entry->client = client;
-  entry->room = room_name;
-  entry->private_key = GNUNET_RSA_decode_key (&cmsg->private_key);
-  if (entry->private_key == NULL)
-    {
-      GNUNET_GE_BREAK (NULL, 0);
-      GNUNET_free (room_name);
-      GNUNET_free (entry);
-      return GNUNET_SYSERR;
-    }
-  GNUNET_RSA_get_public_key (entry->private_key, &pkey);
-  GNUNET_hash (&pkey, sizeof (GNUNET_RSA_PublicKey), &entry->id);
-  entry->msg_options = ntohl (cmsg->msg_options);
-
-
-  nmsg = GNUNET_malloc (sizeof (CS_chat_MESSAGE_JoinNotification) + meta_len);
-  nmsg->header.type = htons (GNUNET_CS_PROTO_CHAT_JOIN_NOTIFICATION);
-  nmsg->header.size =
-    htons (sizeof (CS_chat_MESSAGE_JoinNotification) + meta_len);
-  nmsg->msg_options = cmsg->msg_options;
-  nmsg->public_key = pkey;
-  memcpy (&nmsg[1], &roomptr[room_name_len], meta_len);
-  GNUNET_mutex_lock (chatMutex);
-  entry->next = client_list_head;
-  client_list_head = entry;
-  while (entry != NULL)
-    {
-      if (0 == strcmp (room_name, entry->room))
-        coreAPI->cs_send_message (entry->client, &nmsg->header, GNUNET_YES);
-      entry = entry->next;
-    }
-  GNUNET_mutex_unlock (chatMutex);
-  GNUNET_free (nmsg);
-  return GNUNET_OK;
-}
-
-static void
-chatClientExitHandler (struct GNUNET_ClientHandle *client)
-{
-  struct GNUNET_CS_chat_client *entry;
-  struct GNUNET_CS_chat_client *pos;
-  struct GNUNET_CS_chat_client *prev;
-  CS_chat_MESSAGE_LeaveNotification lmsg;
-
-  GNUNET_mutex_lock (chatMutex);
-  pos = client_list_head;
-  prev = NULL;
-  while ((pos != NULL) && (pos->client != client))
-    {
-      prev = pos;
-      pos = pos->next;
-    }
-  if (pos == NULL)
-    {
-      GNUNET_mutex_unlock (chatMutex);
-      return;                   /* nothing to do */
-    }
-  if (prev == NULL)
-    client_list_head = pos->next;
-  else
-    prev->next = pos->next;
-  entry = client_list_head;
-  lmsg.header.size = htons (sizeof (CS_chat_MESSAGE_LeaveNotification));
-  lmsg.header.type = htons (GNUNET_CS_PROTO_CHAT_LEAVE_NOTIFICATION);
-  lmsg.reserved = htonl (0);
-  GNUNET_RSA_get_public_key (pos->private_key, &lmsg.user);
-  while (entry != NULL)
-    {
-      if (0 == strcmp (entry->room, pos->room))
-        coreAPI->cs_send_message (entry->client, &lmsg.header, GNUNET_YES);
-      entry = entry->next;
-    }
-  GNUNET_mutex_unlock (chatMutex);
-  GNUNET_free (pos->room);
-  GNUNET_RSA_free_key (pos->private_key);
-  GNUNET_free (pos);
-}
-
-int
-initialize_module_chat (GNUNET_CoreAPIForPlugins * capi)
-{
-  int ok = GNUNET_OK;
-
-  coreAPI = capi;
-  GNUNET_GE_LOG (capi->ectx,
-                 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
-                 _("`%s' registering CS handlers %d and %d\n"),
-                 "chat",
-                 GNUNET_CS_PROTO_CHAT_JOIN_REQUEST,
-                 GNUNET_CS_PROTO_CHAT_TRANSMIT_REQUEST);
-
-  if (GNUNET_SYSERR ==
-      capi->cs_disconnect_handler_register (&chatClientExitHandler))
-    ok = GNUNET_SYSERR;
-  if (GNUNET_SYSERR ==
-      capi->cs_handler_register (GNUNET_CS_PROTO_CHAT_JOIN_REQUEST,
-                                 &csHandleChatJoinRequest))
-    ok = GNUNET_SYSERR;
-  if (GNUNET_SYSERR ==
-      capi->cs_handler_register (GNUNET_CS_PROTO_CHAT_TRANSMIT_REQUEST,
-                                 &csHandleTransmitRequest))
-    ok = GNUNET_SYSERR;
-  GNUNET_GE_ASSERT (capi->ectx,
-                    0 == GNUNET_GC_set_configuration_value_string (capi->cfg,
-                                                                   capi->ectx,
-                                                                   "ABOUT",
-                                                                   "chat",
-                                                                   _
-                                                                   ("enables 
P2P-chat (incomplete)")));
-  chatMutex = GNUNET_mutex_create (GNUNET_NO);
-  return ok;
-}
-
-void
-done_module_chat ()
-{
-  coreAPI->cs_disconnect_handler_unregister (&chatClientExitHandler);
-  coreAPI->cs_handler_unregister (GNUNET_CS_PROTO_CHAT_TRANSMIT_REQUEST,
-                                  &csHandleTransmitRequest);
-  coreAPI->cs_handler_unregister (GNUNET_CS_PROTO_CHAT_JOIN_REQUEST,
-                                  &csHandleChatJoinRequest);
-  GNUNET_mutex_destroy (chatMutex);
-  coreAPI = NULL;
-}
-
-
-/* end of chat.c */

Modified: GNUnet/src/applications/chat/chat.h
===================================================================
--- GNUnet/src/applications/chat/chat.h 2008-05-31 19:24:20 UTC (rev 6944)
+++ GNUnet/src/applications/chat/chat.h 2008-05-31 19:28:26 UTC (rev 6945)
@@ -22,7 +22,7 @@
  * @author Christian Grothoff
  * @author Nathan Evans
  * @file chat.h
- **/
+ */
 #ifndef CHAT_H
 #define CHAT_H
 

Deleted: GNUnet/src/applications/chat/chat_p2p.c
===================================================================
--- GNUnet/src/applications/chat/chat_p2p.c     2008-05-31 19:24:20 UTC (rev 
6944)
+++ GNUnet/src/applications/chat/chat_p2p.c     2008-05-31 19:28:26 UTC (rev 
6945)
@@ -1,57 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2008 Christian Grothoff (and other contributing authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @author Nathan Evans
- * @file applications/chat/chat_p2p.c
- */
-#include "chat_p2p.h"
-
-int
-p2pHandleChatJoinRequest (struct GNUNET_ClientHandle *client,
-                          const GNUNET_MessageHeader * message)
-{
-  return GNUNET_SYSERR;
-}
-
-int
-p2pHandleChatMSG (struct GNUNET_ClientHandle *client,
-                  const GNUNET_MessageHeader * message)
-{
-  return GNUNET_SYSERR;
-}
-
-int
-p2pSendChatMSG (const GNUNET_MessageHeader * message)
-{
-  return GNUNET_SYSERR;
-}
-
-int
-p2pGetRoomList ()
-{
-  return GNUNET_SYSERR;
-}
-
-int
-p2pSendRoomList ()
-{
-  return GNUNET_SYSERR;
-}

Deleted: GNUnet/src/applications/chat/chat_p2p.h
===================================================================
--- GNUnet/src/applications/chat/chat_p2p.h     2008-05-31 19:24:20 UTC (rev 
6944)
+++ GNUnet/src/applications/chat/chat_p2p.h     2008-05-31 19:28:26 UTC (rev 
6945)
@@ -1,58 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2008 Christian Grothoff (and other contributing authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @author Nathan Evans
- * @file applications/chat/chat_p2p.h
- *
- * TODO:
- * - change all GNUNET_MessageHandler arguments
- *   to the specific interesting values (chat_p2p.c
- *   should not have to parse them again -- chat.c already did!);
- *   Also, that way, this API becomes independent of
- *   changes to the CS-protocol!
- * - define callbacks for how the P2P code will notify CS
- *   about new messages / users joining the room, etc.
- * - instead of passing the ClientHandle, pass something useful
- *   like the private RSA key or so.
- *
- */
-#ifndef CHATP2P_H
-#define CHATP2P_H
-
-#include "chat.h"
-
-int
-p2pHandleChatJoinRequest (struct GNUNET_ClientHandle *client,
-                          const GNUNET_MessageHeader * message);
-
-int
-p2pHandleChatMSG (struct GNUNET_ClientHandle *client,
-                  const GNUNET_MessageHeader * message);
-
-int p2pSendChatMSG (const GNUNET_MessageHeader * message);
-
-int p2pGetRoomList (void);
-
-int p2pSendRoomList (void);
-
-#endif
-
-/* end of chat_p2p.h */

Deleted: GNUnet/src/applications/chat/chattest.c
===================================================================
--- GNUnet/src/applications/chat/chattest.c     2008-05-31 19:24:20 UTC (rev 
6944)
+++ GNUnet/src/applications/chat/chattest.c     2008-05-31 19:28:26 UTC (rev 
6945)
@@ -1,158 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2005, 2006, 2007, 2008 Christian Grothoff (and other contributing 
authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-     Boston, MA 02110-1301, USA.
-*/
-
-/**
- * @file applications/chat/chattest.c
- * @brief chat testcase, loopback only
- * @author Christian Grothoff
- * @author Nathan Evans
- */
-
-#include "platform.h"
-#include "gnunet_protocols.h"
-#include "gnunet_chat_lib.h"
-#include "gnunet_testing_lib.h"
-#include "gnunet_stats_lib.h"
-#include "gnunet_util.h"
-#include "gnunet_core.h"
-
-#define START_PEERS 1
-
-static struct GNUNET_GC_Configuration *cfg;
-
-static int
-receive_callback1 (void *cls,
-                   struct GNUNET_CHAT_Room *room,
-                   const char *senderNick,
-                   const char *message,
-                   GNUNET_CronTime timestamp, GNUNET_CHAT_MSG_OPTIONS options)
-{
-  fprintf (stdout, _("`%s' said: %s\n"), senderNick, message);
-  return GNUNET_OK;
-}
-
-static int
-member_list_callback1 (void *cls, const char *senderNick,
-                       int is_joining, GNUNET_CronTime timestamp)
-{
-  fprintf (stdout, is_joining
-           ? _("`%s' entered the room\n")
-           : _("`%s' left the room\n"), senderNick);
-  return GNUNET_OK;
-}
-
-static int
-receive_callback2 (void *cls,
-                   struct GNUNET_CHAT_Room *room,
-                   const char *senderNick,
-                   const char *message,
-                   GNUNET_CronTime timestamp, GNUNET_CHAT_MSG_OPTIONS options)
-{
-  fprintf (stdout, _("`%s' said: %s\n"), senderNick, message);
-  return GNUNET_OK;
-}
-
-static int
-member_list_callback2 (void *cls, const char *senderNick,
-                       int is_joining, GNUNET_CronTime timestamp)
-{
-  fprintf (stdout, is_joining
-           ? _("`%s' entered the room\n")
-           : _("`%s' left the room\n"), senderNick);
-  return GNUNET_OK;
-}
-
-
-
-/**
- * Testcase to test chat.
- * @return 0: ok, -1: error
- */
-int
-main (int argc, char **argv)
-{
-  struct GNUNET_TESTING_DaemonContext *peers;
-  int ret;
-  struct GNUNET_CHAT_Room *r1;
-  struct GNUNET_CHAT_Room *r2;
-  GNUNET_RSA_PublicKey me;
-  struct GNUNET_RSA_PrivateKey *key = NULL;
-
-  ret = 0;
-  cfg = GNUNET_GC_create ();
-  if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
-    {
-      GNUNET_GC_free (cfg);
-      return -1;
-    }
-  GNUNET_disable_entropy_gathering ();
-  key = GNUNET_RSA_create_key ();
-  GNUNET_RSA_get_public_key (key, &me);
-#if START_PEERS
-  peers = GNUNET_TESTING_start_daemons ("tcp",
-                                        "chat stats",
-                                        "/tmp/gnunet-chat-test/",
-                                        2087, 10, 1);
-  if (peers == NULL)
-    {
-      fprintf (stderr, "Failed to start the gnunetd daemons!\n");
-      GNUNET_GC_free (cfg);
-      return -1;
-    }
-#endif
-  r1 =
-    GNUNET_CHAT_join_room (NULL, cfg, "nicktest1", "testroom", &me, key, "",
-                           &receive_callback1, NULL, &member_list_callback1,
-                           NULL);
-  if (r1 == NULL)
-    {
-      ret = 1;
-      goto CLEANUP;
-    }
-  r2 =
-    GNUNET_CHAT_join_room (NULL, cfg, "nicktest2", "testroom", &me, key, "",
-                           &receive_callback2, NULL, &member_list_callback2,
-                           NULL);
-  if (r2 == NULL)
-    {
-      ret = 1;
-      goto CLEANUP;
-    }
-
-  GNUNET_CHAT_send_message (r1, "test message 1", NULL, NULL,
-                            GNUNET_CHAT_MSG_OPTION_NONE, NULL);
-
-  GNUNET_CHAT_send_message (r2, "test message 2", NULL, NULL,
-                            GNUNET_CHAT_MSG_OPTION_NONE, NULL);
-
-CLEANUP:
-  if (r1 != NULL)
-    GNUNET_CHAT_leave_room (r1);
-  if (r2 != NULL)
-    GNUNET_CHAT_leave_room (r2);
-
-#if START_PEERS
-  GNUNET_TESTING_stop_daemons (peers);
-#endif
-  GNUNET_GC_free (cfg);
-  return ret;
-}
-
-/* end of chattest.c */

Deleted: GNUnet/src/applications/chat/check.conf
===================================================================
--- GNUnet/src/applications/chat/check.conf     2008-05-31 19:24:20 UTC (rev 
6944)
+++ GNUnet/src/applications/chat/check.conf     2008-05-31 19:28:26 UTC (rev 
6945)
@@ -1,16 +0,0 @@
-# General settings
-[GNUNET]
-GNUNET_HOME = "/tmp/gnunet-chat-test/"
-LOGLEVEL = "WARNING"
-LOGFILE = ""
-PROCESS-PRIORITY = "NORMAL"
-
-# Network options for the clients
-[NETWORK]
-HOST = "localhost:2087"
-
-
-[TESTING]
-WEAKRANDOM = YES
-
-

Deleted: GNUnet/src/applications/chat/clientapi.c
===================================================================
--- GNUnet/src/applications/chat/clientapi.c    2008-05-31 19:24:20 UTC (rev 
6944)
+++ GNUnet/src/applications/chat/clientapi.c    2008-05-31 19:28:26 UTC (rev 
6945)
@@ -1,489 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2008 Christian Grothoff (and other contributing authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file applications/chat/clientapi.c
- * @brief convenience API to the chat application
- * @author Christian Grothoff
- * @author Nathan Evans
- */
-
-#include "platform.h"
-#include "gnunet_util.h"
-#include "gnunet_protocols.h"
-#include "gnunet_chat_lib.h"
-#include "gnunet_directories.h"
-#include "chat.h"
-
-#define NICK_IDENTITY_PREFIX ".chat_identity_"
-
-/**
- * Handle for a (joined) chat room.
- */
-struct GNUNET_CHAT_Room
-{
-  struct GNUNET_ClientServerConnection *sock;
-
-  struct GNUNET_ThreadHandle *listen_thread;
-
-  struct GNUNET_GE_Context *ectx;
-
-  struct GNUNET_GC_Configuration *cfg;
-
-  struct GNUNET_ECRS_MetaData *member_info;
-
-  char *room_name;
-
-  GNUNET_RSA_PrivateKeyEncoded *my_private_key;
-
-  GNUNET_CHAT_MessageCallback message_callback;
-
-  void *message_callback_cls;
-
-  GNUNET_CHAT_MemberListCallback member_list_callback;
-
-  void *member_list_callback_cls;
-
-  GNUNET_CHAT_MessageConfirmation confirmation_callback;
-
-  void *confirmation_cls;
-
-  int shutdown_flag;
-
-  unsigned int sequence_number;
-
-};
-
-static int
-GNUNET_CHAT_rejoin_room (struct GNUNET_CHAT_Room *chat_room)
-{
-  CS_chat_MESSAGE_JoinRequest *join_msg;
-  unsigned int size_of_join;
-  unsigned int room_len;
-  unsigned int meta_len;
-  char *room;
-
-  meta_len =
-    GNUNET_ECRS_meta_data_get_serialized_size (chat_room->member_info,
-                                               GNUNET_YES);
-  room_len = strlen (chat_room->room_name);
-  size_of_join = sizeof (CS_chat_MESSAGE_JoinRequest) + meta_len + room_len;
-  if (size_of_join >= GNUNET_MAX_BUFFER_SIZE - 8)
-    return GNUNET_SYSERR;
-  join_msg = GNUNET_malloc (size_of_join);
-  join_msg->header.size = htons (size_of_join);
-  join_msg->header.type = htons (GNUNET_CS_PROTO_CHAT_JOIN_REQUEST);
-  join_msg->room_name_len = htons (room_len);
-  room = (char *) &join_msg[1];
-  memcpy (room, chat_room->room_name, room_len);
-  if (GNUNET_SYSERR ==
-      GNUNET_ECRS_meta_data_serialize (chat_room->ectx,
-                                       chat_room->member_info,
-                                       &room[room_len], meta_len, GNUNET_YES))
-    {
-      GNUNET_free (join_msg);
-      return GNUNET_SYSERR;
-    }
-  if (GNUNET_SYSERR ==
-      GNUNET_client_connection_write (chat_room->sock, &join_msg->header))
-    {
-      GNUNET_free (join_msg);
-      return GNUNET_SYSERR;
-    }
-  GNUNET_free (join_msg);
-  return GNUNET_OK;
-}
-
-/**
- * Listen for incoming messages on this chat room.  When received,
- * call the proper client callback.  Also, support servers going
- * away/coming back (i.e. rejoin chat room to keep server state up to
- * date)...
- */
-static void *
-poll_thread (void *rcls)
-{
-  struct GNUNET_CHAT_Room *room = rcls;
-  GNUNET_MessageHeader *reply;
-  CS_chat_MESSAGE_ConfirmationReceipt *receipt;
-  CS_chat_MESSAGE_LeaveNotification *leave_msg;
-  CS_chat_MESSAGE_JoinNotification *join_msg;
-  CS_chat_MESSAGE_ReceiveNotification *received_msg;
-  struct GNUNET_ECRS_MetaData *meta;
-  unsigned int size;
-  unsigned int meta_len;
-  unsigned int msg_len;
-  char *message_content;
-  int disconnected;
-  int malformed;
-  int ret;
-
-  disconnected = GNUNET_NO;
-  malformed = GNUNET_NO;
-  ret = GNUNET_OK;
-  reply = NULL;
-  while ((ret == GNUNET_OK) && (room->shutdown_flag != GNUNET_YES))
-    {
-      if (malformed)
-        {
-          GNUNET_GE_BREAK (NULL, 0);
-          GNUNET_client_connection_close_temporarily (room->sock);
-          disconnected = GNUNET_YES;
-          malformed = GNUNET_NO;
-        }
-      if (reply != NULL)
-        {
-          GNUNET_free (reply);
-          reply = NULL;
-        }
-      if (disconnected)
-        {
-          GNUNET_thread_sleep (15 * GNUNET_CRON_SECONDS);
-          if (GNUNET_client_connection_ensure_connected (room->sock) ==
-              GNUNET_OK)
-            {
-              /* send join! */
-              disconnected = GNUNET_NO;
-              GNUNET_CHAT_rejoin_room (room);
-              continue;
-            }
-          else
-            break;
-        }
-      reply = NULL;
-      if (GNUNET_OK != GNUNET_client_connection_read (room->sock, &reply))
-        {
-          disconnected = GNUNET_YES;
-          continue;
-        }
-      size = ntohs (reply->size);
-      switch (ntohs (reply->type))
-        {
-        case GNUNET_CS_PROTO_CHAT_JOIN_NOTIFICATION:
-          if (size < sizeof (CS_chat_MESSAGE_JoinNotification))
-            {
-              malformed = GNUNET_YES;
-              continue;
-            }
-          join_msg = (CS_chat_MESSAGE_JoinNotification *) reply;
-          meta_len = size - sizeof (CS_chat_MESSAGE_JoinNotification);
-          meta = GNUNET_ECRS_meta_data_deserialize (room->ectx,
-                                                    (const char *)
-                                                    &join_msg[1], meta_len);
-          if (meta == NULL)
-            {
-              malformed = GNUNET_YES;
-              continue;
-            }
-          room->member_list_callback (room->member_list_callback_cls,
-                                      meta, &join_msg->public_key);
-          break;
-        case GNUNET_CS_PROTO_CHAT_LEAVE_NOTIFICATION:
-          if (size < sizeof (CS_chat_MESSAGE_LeaveNotification))
-            {
-              malformed = GNUNET_YES;
-              continue;
-            }
-          leave_msg = (CS_chat_MESSAGE_LeaveNotification *) reply;
-          room->member_list_callback (room->member_list_callback_cls,
-                                      NULL, &leave_msg->user);
-          break;
-        case GNUNET_CS_PROTO_CHAT_MESSAGE_NOTIFICATION:
-          if (size < sizeof (CS_chat_MESSAGE_ReceiveNotification))
-            {
-              malformed = GNUNET_YES;
-              continue;
-            }
-          received_msg = (CS_chat_MESSAGE_ReceiveNotification *) reply;
-          msg_len = size - sizeof (CS_chat_MESSAGE_ReceiveNotification);
-          message_content = GNUNET_malloc (msg_len + 1);
-          memcpy (message_content, &received_msg[1], msg_len);
-          message_content[msg_len] = '\0';
-          room->message_callback (room->message_callback_cls,
-                                  room,
-                                  &received_msg->sender,
-                                  message_content,
-                                  ntohl (received_msg->msg_options));
-          GNUNET_free (message_content);
-          break;
-        case GNUNET_CS_PROTO_CHAT_CONFIRMATION_RECEIPT:
-          if (size < sizeof (CS_chat_MESSAGE_ConfirmationReceipt))
-            {
-              malformed = GNUNET_YES;
-              continue;
-            }
-          receipt = (CS_chat_MESSAGE_ConfirmationReceipt *) reply;
-          if (room->confirmation_callback != NULL)
-            room->confirmation_callback (room->confirmation_cls,
-                                         room,
-                                         ntohl (receipt->sequence_number),
-                                         GNUNET_ntohll (receipt->timestamp),
-                                         &receipt->target,
-                                         &receipt->content,
-                                         &receipt->signature);
-          break;
-        default:
-          GNUNET_GE_BREAK (NULL, 0);
-          break;
-        }
-    }
-  GNUNET_free_non_null (reply);
-  return NULL;
-}
-
-#if 0
-/**
- * List all of the (publically visible) chat rooms.
- * @return number of rooms on success, GNUNET_SYSERR if iterator aborted
- */
-int
-GNUNET_CHAT_list_rooms (struct GNUNET_GE_Context *ectx,
-                        struct GNUNET_GC_Configuration *cfg,
-                        GNUNET_CHAT_RoomIterator it, void *cls)
-{
-  return GNUNET_SYSERR;
-}
-#endif
-
-/**
- * Returns the private key on success,
- * NULL on error.
- */
-static GNUNET_RSA_PrivateKeyEncoded *
-GNUNET_CHAT_initPrivateKey (struct GNUNET_GE_Context *ectx,
-                            struct GNUNET_GC_Configuration *cfg,
-                            const char *nick_name)
-{
-  char *gnHome;
-  char *keyfile;
-  GNUNET_RSA_PrivateKeyEncoded *encPrivateKey;
-  struct GNUNET_RSA_PrivateKey *privKey;
-  unsigned short len;
-  int res;
-
-  if (-1 == GNUNET_GC_get_configuration_value_filename (cfg,
-                                                        "PATHS",
-                                                        "GNUNET_HOME",
-                                                        
GNUNET_DEFAULT_HOME_DIRECTORY,
-                                                        &gnHome))
-    return NULL;
-  GNUNET_disk_directory_create (ectx, gnHome);
-  if (GNUNET_YES != GNUNET_disk_directory_test (ectx, gnHome))
-    {
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_FATAL | GNUNET_GE_ADMIN | GNUNET_GE_USER |
-                     GNUNET_GE_IMMEDIATE,
-                     _("Failed to access GNUnet home directory `%s'\n"),
-                     gnHome);
-      GNUNET_free (gnHome);
-      return NULL;
-    }
-
-  /* read or create public key */
-  keyfile =
-    GNUNET_malloc (strlen (gnHome) + strlen (NICK_IDENTITY_PREFIX) +
-                   strlen (nick_name) + 2);
-  strcpy (keyfile, gnHome);
-  GNUNET_free (gnHome);
-  if (keyfile[strlen (keyfile) - 1] != DIR_SEPARATOR)
-    strcat (keyfile, DIR_SEPARATOR_STR);
-  strcat (keyfile, NICK_IDENTITY_PREFIX);
-  strcat (keyfile, nick_name);
-
-  res = 0;
-  if (GNUNET_YES == GNUNET_disk_file_test (ectx, keyfile))
-    {
-      res =
-        GNUNET_disk_file_read (ectx, keyfile, sizeof (unsigned short), &len);
-    }
-  encPrivateKey = NULL;
-  if (res == sizeof (unsigned short))
-    {
-      encPrivateKey =
-        (GNUNET_RSA_PrivateKeyEncoded *) GNUNET_malloc (ntohs (len));
-      if (ntohs (len) !=
-          GNUNET_disk_file_read (ectx, keyfile, ntohs (len), encPrivateKey))
-        {
-          GNUNET_free (encPrivateKey);
-          GNUNET_GE_LOG (ectx,
-                         GNUNET_GE_WARNING | GNUNET_GE_USER |
-                         GNUNET_GE_IMMEDIATE | GNUNET_GE_ADMIN,
-                         _
-                         ("Existing key in file `%s' failed format check, 
creating new key.\n"),
-                         keyfile);
-          encPrivateKey = NULL;
-        }
-    }
-  if (encPrivateKey == NULL)
-    {                           /* make new hostkey */
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_INFO | GNUNET_GE_USER | GNUNET_GE_BULK,
-                     _
-                     ("Creating new key for this nickname (this may take a 
while).\n"));
-      privKey = GNUNET_RSA_create_key ();
-      GNUNET_GE_ASSERT (ectx, privKey != NULL);
-      encPrivateKey = GNUNET_RSA_encode_key (privKey);
-      GNUNET_GE_ASSERT (ectx, encPrivateKey != NULL);
-      GNUNET_disk_file_write (ectx,
-                              keyfile,
-                              encPrivateKey, ntohs (encPrivateKey->len),
-                              "600");
-      GNUNET_RSA_free_key (privKey);
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_INFO | GNUNET_GE_USER | GNUNET_GE_BULK,
-                     _("Done creating key.\n"));
-    }
-  GNUNET_free (keyfile);
-  GNUNET_GE_ASSERT (ectx, encPrivateKey != NULL);
-  return encPrivateKey;
-}
-
-/**
- * Join a chat room.
- *
- * @param nick_name nickname of the user joining (used to
- *                  determine which public key to use);
- *                  the nickname should probably also
- *                  be used in the member_info (as "EXTRACTOR_TITLE")
- * @param member_info information about the joining member
- * @param memberInfo public information about you
- * @param messageCallback which function to call if a message has
- *        been received?
- * @param message_cls argument to callback
- * @param memberCallback which function to call for join/leave notifications
- * @param confirmationCallback which function to call for confirmations (maybe 
NULL)
- * @return NULL on error
- */
-struct GNUNET_CHAT_Room *
-GNUNET_CHAT_join_room (struct GNUNET_GE_Context *ectx,
-                       struct GNUNET_GC_Configuration *cfg,
-                       const char *nick_name,
-                       struct GNUNET_ECRS_MetaData *member_info,
-                       const char *room_name,
-                       GNUNET_CHAT_MessageCallback messageCallback,
-                       void *message_cls,
-                       GNUNET_CHAT_MemberListCallback memberCallback,
-                       void *member_cls,
-                       GNUNET_CHAT_MessageConfirmation confirmationCallback,
-                       void *confirmation_cls)
-{
-  struct GNUNET_CHAT_Room *chat_room;
-  struct GNUNET_ClientServerConnection *sock;
-  GNUNET_RSA_PrivateKeyEncoded *key;
-
-  key = GNUNET_CHAT_initPrivateKey (ectx, cfg, nick_name);
-  if (key == NULL)
-    return NULL;
-  sock = GNUNET_client_connection_create (ectx, cfg);
-  if (sock == NULL)
-    {
-      GNUNET_free (key);
-      return NULL;
-    }
-  chat_room = GNUNET_malloc (sizeof (struct GNUNET_CHAT_Room));
-  chat_room->room_name = GNUNET_strdup (room_name);
-  chat_room->member_info = GNUNET_ECRS_meta_data_duplicate (member_info);
-  chat_room->my_private_key = key;
-  chat_room->message_callback = messageCallback;
-  chat_room->message_callback_cls = message_cls;
-  chat_room->member_list_callback = memberCallback;
-  chat_room->member_list_callback_cls = member_cls;
-  chat_room->confirmation_callback = confirmationCallback;
-  chat_room->confirmation_cls = confirmation_cls;
-  chat_room->ectx = ectx;
-  chat_room->cfg = cfg;
-  chat_room->sock = sock;
-  chat_room->listen_thread =
-    GNUNET_thread_create (&poll_thread, chat_room, 1024 * 2);
-  if (chat_room->listen_thread == NULL)
-    {
-      GNUNET_free (chat_room->room_name);
-      GNUNET_client_connection_destroy (chat_room->sock);
-      GNUNET_ECRS_meta_data_destroy (chat_room->member_info);
-      GNUNET_free (chat_room);
-      GNUNET_free (key);
-      return NULL;
-    }
-  if (GNUNET_SYSERR == GNUNET_CHAT_rejoin_room (chat_room))
-    {
-      GNUNET_CHAT_leave_room (chat_room);
-      return NULL;
-    }
-  return chat_room;
-}
-
-/**
- * Leave a chat room.
- */
-void
-GNUNET_CHAT_leave_room (struct GNUNET_CHAT_Room *chat_room)
-{
-  void *unused;
-
-  chat_room->shutdown_flag = GNUNET_YES;
-  GNUNET_client_connection_close_forever (chat_room->sock);
-  GNUNET_thread_stop_sleep (chat_room->listen_thread);
-  GNUNET_thread_join (chat_room->listen_thread, &unused);
-  GNUNET_free (chat_room->room_name);
-  GNUNET_ECRS_meta_data_destroy (chat_room->member_info);
-  GNUNET_client_connection_destroy (chat_room->sock);
-  GNUNET_free (chat_room->my_private_key);
-  GNUNET_free (chat_room);
-}
-
-/**
- * Send a message.
- *
- * @param receiver use NULL to send to everyone in the room
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
-int
-GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room,
-                          const char *message,
-                          GNUNET_CHAT_MSG_OPTIONS options,
-                          const GNUNET_RSA_PublicKey * receiver,
-                          unsigned int *sequence_number)
-{
-  int ret = GNUNET_OK;
-  CS_chat_MESSAGE_TransmitRequest *msg_to_send;
-  unsigned int msg_size;
-
-  msg_size = strlen (message) + sizeof (CS_chat_MESSAGE_TransmitRequest);
-  if (msg_size > GNUNET_MAX_BUFFER_SIZE - 8)
-    return GNUNET_SYSERR;
-  msg_to_send = GNUNET_malloc (msg_size);
-  msg_to_send->header.size = htons (msg_size);
-  msg_to_send->header.type = htons (GNUNET_CS_PROTO_CHAT_TRANSMIT_REQUEST);
-  msg_to_send->msg_options = htonl (options);
-  *sequence_number = room->sequence_number++;
-  msg_to_send->sequence_number = htonl (*sequence_number);
-  msg_to_send->reserved = htonl (0);
-  if (receiver == NULL)
-    memset (&msg_to_send->target, 0, sizeof (GNUNET_HashCode));
-  else
-    GNUNET_hash (receiver,
-                 sizeof (GNUNET_RSA_PublicKey), &msg_to_send->target);
-  memcpy (&msg_to_send[1], message, strlen (message));
-  ret = GNUNET_client_connection_write (room->sock, &msg_to_send->header);
-  GNUNET_free (msg_to_send);
-  return ret;
-}
-
-/* end of clientapi.c */

Deleted: GNUnet/src/applications/chat/gnunet-chat.c
===================================================================
--- GNUnet/src/applications/chat/gnunet-chat.c  2008-05-31 19:24:20 UTC (rev 
6944)
+++ GNUnet/src/applications/chat/gnunet-chat.c  2008-05-31 19:28:26 UTC (rev 
6945)
@@ -1,200 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2007, 2008 Christian Grothoff (and other contributing authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file applications/chat/gnunet-chat.c
- * @brief Minimal chat command line tool
- * @author Christian Grothoff
- * @author Nathan Evans
- */
-
-#include "platform.h"
-#include "gnunet_protocols.h"
-#include "gnunet_directories.h"
-#include "gnunet_chat_lib.h"
-#include "gnunet_ecrs_lib.h"
-
-#define MAX_MESSAGE_LENGTH 1024
-
-#define QUIT_COMMAND "quit"
-
-static struct GNUNET_GC_Configuration *cfg;
-
-static struct GNUNET_GE_Context *ectx;
-
-static char *cfgFilename = GNUNET_DEFAULT_CLIENT_CONFIG_FILE;
-
-static char *nickname;
-
-static char *room_name = "gnunet";
-
-/**
- * All gnunet-chat command line options
- */
-static struct GNUNET_CommandLineOption gnunetchatOptions[] = {
-  GNUNET_COMMAND_LINE_OPTION_HELP (gettext_noop ("Join a chat on GNUnet.")),   
 /* -h */
-  GNUNET_COMMAND_LINE_OPTION_HOSTNAME,  /* -H */
-  GNUNET_COMMAND_LINE_OPTION_LOGGING,   /* -L */
-  {'n', "nick", "NAME",
-   gettext_noop ("set the nickname to use (required)"),
-   1, &GNUNET_getopt_configure_set_string, &nickname},
-  {'r', "room", "NAME",
-   gettext_noop ("set the chat room to join"),
-   1, &GNUNET_getopt_configure_set_string, &room_name},
-  GNUNET_COMMAND_LINE_OPTION_VERSION (PACKAGE_VERSION), /* -v */
-  GNUNET_COMMAND_LINE_OPTION_VERBOSE,
-  GNUNET_COMMAND_LINE_OPTION_END,
-};
-
-/**
- * A message was sent in the chat to us.
- *
- * @param timestamp when was the message sent?
- * @param senderNick what is the nickname of the sender? (maybe NULL)
- * @param message the message (maybe NULL, especially if confirmation
- *        is requested before delivery; the protocol will ensure
- *        that this function is called again with the full message
- *        if a confirmation is transmitted; if the message is NULL,
- *        the user is merely asked if engaging in the exchange is ok
- * @param room in which room was the message received?
- * @param options options for the message
- * @return GNUNET_OK to accept the message now, GNUNET_NO to
- *         accept (but user is away), GNUNET_SYSERR to signal denied delivery
- */
-static int
-receive_callback (void *cls,
-                  struct GNUNET_CHAT_Room *room,
-                  const GNUNET_HashCode * sender,
-                  const char *message, GNUNET_CHAT_MSG_OPTIONS options)
-{
-  fprintf (stdout, _("`%s' said: %s\n"), "FIXME", message);
-  return GNUNET_OK;
-}
-
-static int
-member_list_callback (void *cls,
-                      const struct GNUNET_ECRS_MetaData *member_info,
-                      const GNUNET_RSA_PublicKey * member_id)
-{
-  fprintf (stdout, member_info != NULL
-           ? _("`%s' entered the room\n")
-           : _("`%s' left the room\n"), "FIXME");
-  return GNUNET_OK;
-}
-
-/**
- * Message delivery confirmations.
- *
- * @param timestamp when was the message received?
- * @param message the message (maybe NULL)
- * @param room in which room was the message received?
- * @param receipt signature confirming delivery (maybe NULL, only
- *        if confirmation was requested)
- * @return GNUNET_OK to continue, GNUNET_SYSERR to refuse processing further
- *         confirmations from anyone for this message
- */
-static int
-confirmation_callback (void *cls,
-                       struct GNUNET_CHAT_Room *room,
-                       unsigned int orig_seq_number,
-                       GNUNET_CronTime timestamp,
-                       const GNUNET_HashCode * receiver,
-                       const GNUNET_HashCode * msg_hash,
-                       const GNUNET_RSA_Signature * receipt)
-{
-  return GNUNET_OK;
-}
-
-/**
- * GNUnet-chat main.
- *
- * @param argc number of arguments from the command line
- * @param argv command line arguments
- * @return  0: ok, otherwise error
- */
-int
-main (int argc, char **argv)
-{
-  struct GNUNET_CHAT_Room *room;
-  struct GNUNET_RSA_PrivateKey *my_priv;
-  struct GNUNET_ECRS_MetaData *meta;
-  char message[MAX_MESSAGE_LENGTH + 1];
-  unsigned int seq;
-
-  if (GNUNET_SYSERR == GNUNET_init (argc,
-                                    argv,
-                                    "gnunet-chat [OPTIONS]",
-                                    &cfgFilename, gnunetchatOptions, &ectx,
-                                    &cfg))
-    return -1;
-  if (nickname == NULL)
-    {
-      fprintf (stderr, _("You must specify a nickname\n"));
-      GNUNET_fini (ectx, cfg);
-      return -1;
-    }
-
-  meta = GNUNET_ECRS_meta_data_create ();
-  GNUNET_ECRS_meta_data_insert (meta, EXTRACTOR_TITLE, nickname);
-  room = GNUNET_CHAT_join_room (ectx,
-                                cfg,
-                                nickname,
-                                meta,
-                                room_name,
-                                &receive_callback,
-                                NULL, &member_list_callback, NULL,
-                                &confirmation_callback, NULL);
-  GNUNET_ECRS_meta_data_destroy (meta);
-  if (room == NULL)
-    {
-      fprintf (stderr, _("Failed to join room `%s'\n"), room_name);
-      GNUNET_RSA_free_key (my_priv);
-      GNUNET_fini (ectx, cfg);
-      return -1;
-    }
-  fprintf (stdout,
-           _
-           ("Joined room `%s'.\nType message and hit return to send.\nType 
`%s' when ready to quit.\n"),
-           room_name, QUIT_COMMAND);
-  /* read messages from command line and send */
-  while ((0 != strcmp (message, QUIT_COMMAND)) &&
-         (GNUNET_shutdown_test () == GNUNET_NO))
-    {
-      memset (message, 0, MAX_MESSAGE_LENGTH + 1);
-      if (NULL == fgets (message, MAX_MESSAGE_LENGTH, stdin))
-        break;
-      if (0 == strcmp (message, QUIT_COMMAND))
-        break;
-      if (message[strlen (message) - 1] == '\n')
-        message[strlen (message) - 1] = '\0';
-      if (GNUNET_OK != GNUNET_CHAT_send_message (room,
-                                                 message,
-                                                 GNUNET_CHAT_MSG_OPTION_NONE,
-                                                 NULL, &seq))
-        fprintf (stderr, _("Failed to send message.\n"));
-    }
-
-  GNUNET_CHAT_leave_room (room);
-  GNUNET_RSA_free_key (my_priv);
-  GNUNET_fini (ectx, cfg);
-  return 0;
-}
-
-/* end of gnunet-chat.c */

Modified: GNUnet/src/applications/chat/lib/Makefile.am
===================================================================
--- GNUnet/src/applications/chat/lib/Makefile.am        2008-05-31 19:24:20 UTC 
(rev 6944)
+++ GNUnet/src/applications/chat/lib/Makefile.am        2008-05-31 19:28:26 UTC 
(rev 6945)
@@ -3,46 +3,21 @@
 LDADD = \
  $(top_builddir)/src/util/libgnunetutil.la 
 
-plugindir = $(libdir)/GNUnet
-
-plugin_LTLIBRARIES = \
-  libgnunetmodule_chat.la
-
-lib_LTLIBRARIES = \
-  libgnunetchat_api.la
-
-bin_PROGRAMS = \
- gnunet-chat
-
-gnunet_chat_SOURCES = \
- gnunet-chat.c         
-gnunet_chat_LDADD = \
-  $(top_builddir)/src/applications/chat/libgnunetchat_api.la 
-
 libgnunetchat_api_la_SOURCES = \
   clientapi.c 
 libgnunetchat_api_la_LIBADD = \
   $(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
   $(top_builddir)/src/util/libgnunetutil.la 
 
-libgnunetmodule_chat_la_SOURCES = \
-  chat.c chat.h
-libgnunetmodule_chat_la_LIBADD = \
-  $(top_builddir)/src/util/libgnunetutil.la
-libgnunetmodule_chat_la_LDFLAGS = \
-  -export-dynamic -avoid-version -module
-
-
-
 check_PROGRAMS = \
-  chattest
+  loopback_test
 
 TESTS = $(check_PROGRAMS)
 
-chattest_SOURCES = \
-  chattest.c 
+loopback_test_SOURCES = \
+  loopback_test.c 
 chattest_LDADD = \
   $(top_builddir)/src/applications/testing/libgnunettesting_api.la \
   $(top_builddir)/src/applications/stats/libgnunetstats_api.la \
-  $(top_builddir)/src/applications/chat/libgnunetchat_api.la \
+  $(top_builddir)/src/applications/chat/lib/libgnunetchat_api.la \
   $(top_builddir)/src/util/libgnunetutil.la 

Copied: GNUnet/src/applications/chat/lib/check.conf (from rev 6943, 
GNUnet/src/applications/chat/check.conf)
===================================================================
--- GNUnet/src/applications/chat/lib/check.conf                         (rev 0)
+++ GNUnet/src/applications/chat/lib/check.conf 2008-05-31 19:28:26 UTC (rev 
6945)
@@ -0,0 +1,16 @@
+# General settings
+[GNUNET]
+GNUNET_HOME = "/tmp/gnunet-chat-test/"
+LOGLEVEL = "WARNING"
+LOGFILE = ""
+PROCESS-PRIORITY = "NORMAL"
+
+# Network options for the clients
+[NETWORK]
+HOST = "localhost:2087"
+
+
+[TESTING]
+WEAKRANDOM = YES
+
+

Copied: GNUnet/src/applications/chat/lib/loopback_test.c (from rev 6943, 
GNUnet/src/applications/chat/chattest.c)
===================================================================
--- GNUnet/src/applications/chat/lib/loopback_test.c                            
(rev 0)
+++ GNUnet/src/applications/chat/lib/loopback_test.c    2008-05-31 19:28:26 UTC 
(rev 6945)
@@ -0,0 +1,158 @@
+/*
+     This file is part of GNUnet.
+     (C) 2005, 2006, 2007, 2008 Christian Grothoff (and other contributing 
authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+     Boston, MA 02110-1301, USA.
+*/
+
+/**
+ * @file applications/chat/chattest.c
+ * @brief chat testcase, loopback only
+ * @author Christian Grothoff
+ * @author Nathan Evans
+ */
+
+#include "platform.h"
+#include "gnunet_protocols.h"
+#include "gnunet_chat_lib.h"
+#include "gnunet_testing_lib.h"
+#include "gnunet_stats_lib.h"
+#include "gnunet_util.h"
+#include "gnunet_core.h"
+
+#define START_PEERS 1
+
+static struct GNUNET_GC_Configuration *cfg;
+
+static int
+receive_callback1 (void *cls,
+                   struct GNUNET_CHAT_Room *room,
+                   const char *senderNick,
+                   const char *message,
+                   GNUNET_CronTime timestamp, GNUNET_CHAT_MSG_OPTIONS options)
+{
+  fprintf (stdout, _("`%s' said: %s\n"), senderNick, message);
+  return GNUNET_OK;
+}
+
+static int
+member_list_callback1 (void *cls, const char *senderNick,
+                       int is_joining, GNUNET_CronTime timestamp)
+{
+  fprintf (stdout, is_joining
+           ? _("`%s' entered the room\n")
+           : _("`%s' left the room\n"), senderNick);
+  return GNUNET_OK;
+}
+
+static int
+receive_callback2 (void *cls,
+                   struct GNUNET_CHAT_Room *room,
+                   const char *senderNick,
+                   const char *message,
+                   GNUNET_CronTime timestamp, GNUNET_CHAT_MSG_OPTIONS options)
+{
+  fprintf (stdout, _("`%s' said: %s\n"), senderNick, message);
+  return GNUNET_OK;
+}
+
+static int
+member_list_callback2 (void *cls, const char *senderNick,
+                       int is_joining, GNUNET_CronTime timestamp)
+{
+  fprintf (stdout, is_joining
+           ? _("`%s' entered the room\n")
+           : _("`%s' left the room\n"), senderNick);
+  return GNUNET_OK;
+}
+
+
+
+/**
+ * Testcase to test chat.
+ * @return 0: ok, -1: error
+ */
+int
+main (int argc, char **argv)
+{
+  struct GNUNET_TESTING_DaemonContext *peers;
+  int ret;
+  struct GNUNET_CHAT_Room *r1;
+  struct GNUNET_CHAT_Room *r2;
+  GNUNET_RSA_PublicKey me;
+  struct GNUNET_RSA_PrivateKey *key = NULL;
+
+  ret = 0;
+  cfg = GNUNET_GC_create ();
+  if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
+    {
+      GNUNET_GC_free (cfg);
+      return -1;
+    }
+  GNUNET_disable_entropy_gathering ();
+  key = GNUNET_RSA_create_key ();
+  GNUNET_RSA_get_public_key (key, &me);
+#if START_PEERS
+  peers = GNUNET_TESTING_start_daemons ("tcp",
+                                        "chat stats",
+                                        "/tmp/gnunet-chat-test/",
+                                        2087, 10, 1);
+  if (peers == NULL)
+    {
+      fprintf (stderr, "Failed to start the gnunetd daemons!\n");
+      GNUNET_GC_free (cfg);
+      return -1;
+    }
+#endif
+  r1 =
+    GNUNET_CHAT_join_room (NULL, cfg, "nicktest1", "testroom", &me, key, "",
+                           &receive_callback1, NULL, &member_list_callback1,
+                           NULL);
+  if (r1 == NULL)
+    {
+      ret = 1;
+      goto CLEANUP;
+    }
+  r2 =
+    GNUNET_CHAT_join_room (NULL, cfg, "nicktest2", "testroom", &me, key, "",
+                           &receive_callback2, NULL, &member_list_callback2,
+                           NULL);
+  if (r2 == NULL)
+    {
+      ret = 1;
+      goto CLEANUP;
+    }
+
+  GNUNET_CHAT_send_message (r1, "test message 1", NULL, NULL,
+                            GNUNET_CHAT_MSG_OPTION_NONE, NULL);
+
+  GNUNET_CHAT_send_message (r2, "test message 2", NULL, NULL,
+                            GNUNET_CHAT_MSG_OPTION_NONE, NULL);
+
+CLEANUP:
+  if (r1 != NULL)
+    GNUNET_CHAT_leave_room (r1);
+  if (r2 != NULL)
+    GNUNET_CHAT_leave_room (r2);
+
+#if START_PEERS
+  GNUNET_TESTING_stop_daemons (peers);
+#endif
+  GNUNET_GC_free (cfg);
+  return ret;
+}
+
+/* end of chattest.c */

Copied: GNUnet/src/applications/chat/lib/messaging.c (from rev 6944, 
GNUnet/src/applications/chat/clientapi.c)
===================================================================
--- GNUnet/src/applications/chat/lib/messaging.c                                
(rev 0)
+++ GNUnet/src/applications/chat/lib/messaging.c        2008-05-31 19:28:26 UTC 
(rev 6945)
@@ -0,0 +1,489 @@
+/*
+     This file is part of GNUnet.
+     (C) 2008 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file applications/chat/clientapi.c
+ * @brief convenience API to the chat application
+ * @author Christian Grothoff
+ * @author Nathan Evans
+ */
+
+#include "platform.h"
+#include "gnunet_util.h"
+#include "gnunet_protocols.h"
+#include "gnunet_chat_lib.h"
+#include "gnunet_directories.h"
+#include "chat.h"
+
+#define NICK_IDENTITY_PREFIX ".chat_identity_"
+
+/**
+ * Handle for a (joined) chat room.
+ */
+struct GNUNET_CHAT_Room
+{
+  struct GNUNET_ClientServerConnection *sock;
+
+  struct GNUNET_ThreadHandle *listen_thread;
+
+  struct GNUNET_GE_Context *ectx;
+
+  struct GNUNET_GC_Configuration *cfg;
+
+  struct GNUNET_ECRS_MetaData *member_info;
+
+  char *room_name;
+
+  GNUNET_RSA_PrivateKeyEncoded *my_private_key;
+
+  GNUNET_CHAT_MessageCallback message_callback;
+
+  void *message_callback_cls;
+
+  GNUNET_CHAT_MemberListCallback member_list_callback;
+
+  void *member_list_callback_cls;
+
+  GNUNET_CHAT_MessageConfirmation confirmation_callback;
+
+  void *confirmation_cls;
+
+  int shutdown_flag;
+
+  unsigned int sequence_number;
+
+};
+
+static int
+GNUNET_CHAT_rejoin_room (struct GNUNET_CHAT_Room *chat_room)
+{
+  CS_chat_MESSAGE_JoinRequest *join_msg;
+  unsigned int size_of_join;
+  unsigned int room_len;
+  unsigned int meta_len;
+  char *room;
+
+  meta_len =
+    GNUNET_ECRS_meta_data_get_serialized_size (chat_room->member_info,
+                                               GNUNET_YES);
+  room_len = strlen (chat_room->room_name);
+  size_of_join = sizeof (CS_chat_MESSAGE_JoinRequest) + meta_len + room_len;
+  if (size_of_join >= GNUNET_MAX_BUFFER_SIZE - 8)
+    return GNUNET_SYSERR;
+  join_msg = GNUNET_malloc (size_of_join);
+  join_msg->header.size = htons (size_of_join);
+  join_msg->header.type = htons (GNUNET_CS_PROTO_CHAT_JOIN_REQUEST);
+  join_msg->room_name_len = htons (room_len);
+  room = (char *) &join_msg[1];
+  memcpy (room, chat_room->room_name, room_len);
+  if (GNUNET_SYSERR ==
+      GNUNET_ECRS_meta_data_serialize (chat_room->ectx,
+                                       chat_room->member_info,
+                                       &room[room_len], meta_len, GNUNET_YES))
+    {
+      GNUNET_free (join_msg);
+      return GNUNET_SYSERR;
+    }
+  if (GNUNET_SYSERR ==
+      GNUNET_client_connection_write (chat_room->sock, &join_msg->header))
+    {
+      GNUNET_free (join_msg);
+      return GNUNET_SYSERR;
+    }
+  GNUNET_free (join_msg);
+  return GNUNET_OK;
+}
+
+/**
+ * Listen for incoming messages on this chat room.  When received,
+ * call the proper client callback.  Also, support servers going
+ * away/coming back (i.e. rejoin chat room to keep server state up to
+ * date)...
+ */
+static void *
+poll_thread (void *rcls)
+{
+  struct GNUNET_CHAT_Room *room = rcls;
+  GNUNET_MessageHeader *reply;
+  CS_chat_MESSAGE_ConfirmationReceipt *receipt;
+  CS_chat_MESSAGE_LeaveNotification *leave_msg;
+  CS_chat_MESSAGE_JoinNotification *join_msg;
+  CS_chat_MESSAGE_ReceiveNotification *received_msg;
+  struct GNUNET_ECRS_MetaData *meta;
+  unsigned int size;
+  unsigned int meta_len;
+  unsigned int msg_len;
+  char *message_content;
+  int disconnected;
+  int malformed;
+  int ret;
+
+  disconnected = GNUNET_NO;
+  malformed = GNUNET_NO;
+  ret = GNUNET_OK;
+  reply = NULL;
+  while ((ret == GNUNET_OK) && (room->shutdown_flag != GNUNET_YES))
+    {
+      if (malformed)
+        {
+          GNUNET_GE_BREAK (NULL, 0);
+          GNUNET_client_connection_close_temporarily (room->sock);
+          disconnected = GNUNET_YES;
+          malformed = GNUNET_NO;
+        }
+      if (reply != NULL)
+        {
+          GNUNET_free (reply);
+          reply = NULL;
+        }
+      if (disconnected)
+        {
+          GNUNET_thread_sleep (15 * GNUNET_CRON_SECONDS);
+          if (GNUNET_client_connection_ensure_connected (room->sock) ==
+              GNUNET_OK)
+            {
+              /* send join! */
+              disconnected = GNUNET_NO;
+              GNUNET_CHAT_rejoin_room (room);
+              continue;
+            }
+          else
+            break;
+        }
+      reply = NULL;
+      if (GNUNET_OK != GNUNET_client_connection_read (room->sock, &reply))
+        {
+          disconnected = GNUNET_YES;
+          continue;
+        }
+      size = ntohs (reply->size);
+      switch (ntohs (reply->type))
+        {
+        case GNUNET_CS_PROTO_CHAT_JOIN_NOTIFICATION:
+          if (size < sizeof (CS_chat_MESSAGE_JoinNotification))
+            {
+              malformed = GNUNET_YES;
+              continue;
+            }
+          join_msg = (CS_chat_MESSAGE_JoinNotification *) reply;
+          meta_len = size - sizeof (CS_chat_MESSAGE_JoinNotification);
+          meta = GNUNET_ECRS_meta_data_deserialize (room->ectx,
+                                                    (const char *)
+                                                    &join_msg[1], meta_len);
+          if (meta == NULL)
+            {
+              malformed = GNUNET_YES;
+              continue;
+            }
+          room->member_list_callback (room->member_list_callback_cls,
+                                      meta, &join_msg->public_key);
+          break;
+        case GNUNET_CS_PROTO_CHAT_LEAVE_NOTIFICATION:
+          if (size < sizeof (CS_chat_MESSAGE_LeaveNotification))
+            {
+              malformed = GNUNET_YES;
+              continue;
+            }
+          leave_msg = (CS_chat_MESSAGE_LeaveNotification *) reply;
+          room->member_list_callback (room->member_list_callback_cls,
+                                      NULL, &leave_msg->user);
+          break;
+        case GNUNET_CS_PROTO_CHAT_MESSAGE_NOTIFICATION:
+          if (size < sizeof (CS_chat_MESSAGE_ReceiveNotification))
+            {
+              malformed = GNUNET_YES;
+              continue;
+            }
+          received_msg = (CS_chat_MESSAGE_ReceiveNotification *) reply;
+          msg_len = size - sizeof (CS_chat_MESSAGE_ReceiveNotification);
+          message_content = GNUNET_malloc (msg_len + 1);
+          memcpy (message_content, &received_msg[1], msg_len);
+          message_content[msg_len] = '\0';
+          room->message_callback (room->message_callback_cls,
+                                  room,
+                                  &received_msg->sender,
+                                  message_content,
+                                  ntohl (received_msg->msg_options));
+          GNUNET_free (message_content);
+          break;
+        case GNUNET_CS_PROTO_CHAT_CONFIRMATION_RECEIPT:
+          if (size < sizeof (CS_chat_MESSAGE_ConfirmationReceipt))
+            {
+              malformed = GNUNET_YES;
+              continue;
+            }
+          receipt = (CS_chat_MESSAGE_ConfirmationReceipt *) reply;
+          if (room->confirmation_callback != NULL)
+            room->confirmation_callback (room->confirmation_cls,
+                                         room,
+                                         ntohl (receipt->sequence_number),
+                                         GNUNET_ntohll (receipt->timestamp),
+                                         &receipt->target,
+                                         &receipt->content,
+                                         &receipt->signature);
+          break;
+        default:
+          GNUNET_GE_BREAK (NULL, 0);
+          break;
+        }
+    }
+  GNUNET_free_non_null (reply);
+  return NULL;
+}
+
+#if 0
+/**
+ * List all of the (publically visible) chat rooms.
+ * @return number of rooms on success, GNUNET_SYSERR if iterator aborted
+ */
+int
+GNUNET_CHAT_list_rooms (struct GNUNET_GE_Context *ectx,
+                        struct GNUNET_GC_Configuration *cfg,
+                        GNUNET_CHAT_RoomIterator it, void *cls)
+{
+  return GNUNET_SYSERR;
+}
+#endif
+
+/**
+ * Returns the private key on success,
+ * NULL on error.
+ */
+static GNUNET_RSA_PrivateKeyEncoded *
+GNUNET_CHAT_initPrivateKey (struct GNUNET_GE_Context *ectx,
+                            struct GNUNET_GC_Configuration *cfg,
+                            const char *nick_name)
+{
+  char *gnHome;
+  char *keyfile;
+  GNUNET_RSA_PrivateKeyEncoded *encPrivateKey;
+  struct GNUNET_RSA_PrivateKey *privKey;
+  unsigned short len;
+  int res;
+
+  if (-1 == GNUNET_GC_get_configuration_value_filename (cfg,
+                                                        "PATHS",
+                                                        "GNUNET_HOME",
+                                                        
GNUNET_DEFAULT_HOME_DIRECTORY,
+                                                        &gnHome))
+    return NULL;
+  GNUNET_disk_directory_create (ectx, gnHome);
+  if (GNUNET_YES != GNUNET_disk_directory_test (ectx, gnHome))
+    {
+      GNUNET_GE_LOG (ectx,
+                     GNUNET_GE_FATAL | GNUNET_GE_ADMIN | GNUNET_GE_USER |
+                     GNUNET_GE_IMMEDIATE,
+                     _("Failed to access GNUnet home directory `%s'\n"),
+                     gnHome);
+      GNUNET_free (gnHome);
+      return NULL;
+    }
+
+  /* read or create public key */
+  keyfile =
+    GNUNET_malloc (strlen (gnHome) + strlen (NICK_IDENTITY_PREFIX) +
+                   strlen (nick_name) + 2);
+  strcpy (keyfile, gnHome);
+  GNUNET_free (gnHome);
+  if (keyfile[strlen (keyfile) - 1] != DIR_SEPARATOR)
+    strcat (keyfile, DIR_SEPARATOR_STR);
+  strcat (keyfile, NICK_IDENTITY_PREFIX);
+  strcat (keyfile, nick_name);
+
+  res = 0;
+  if (GNUNET_YES == GNUNET_disk_file_test (ectx, keyfile))
+    {
+      res =
+        GNUNET_disk_file_read (ectx, keyfile, sizeof (unsigned short), &len);
+    }
+  encPrivateKey = NULL;
+  if (res == sizeof (unsigned short))
+    {
+      encPrivateKey =
+        (GNUNET_RSA_PrivateKeyEncoded *) GNUNET_malloc (ntohs (len));
+      if (ntohs (len) !=
+          GNUNET_disk_file_read (ectx, keyfile, ntohs (len), encPrivateKey))
+        {
+          GNUNET_free (encPrivateKey);
+          GNUNET_GE_LOG (ectx,
+                         GNUNET_GE_WARNING | GNUNET_GE_USER |
+                         GNUNET_GE_IMMEDIATE | GNUNET_GE_ADMIN,
+                         _
+                         ("Existing key in file `%s' failed format check, 
creating new key.\n"),
+                         keyfile);
+          encPrivateKey = NULL;
+        }
+    }
+  if (encPrivateKey == NULL)
+    {                           /* make new hostkey */
+      GNUNET_GE_LOG (ectx,
+                     GNUNET_GE_INFO | GNUNET_GE_USER | GNUNET_GE_BULK,
+                     _
+                     ("Creating new key for this nickname (this may take a 
while).\n"));
+      privKey = GNUNET_RSA_create_key ();
+      GNUNET_GE_ASSERT (ectx, privKey != NULL);
+      encPrivateKey = GNUNET_RSA_encode_key (privKey);
+      GNUNET_GE_ASSERT (ectx, encPrivateKey != NULL);
+      GNUNET_disk_file_write (ectx,
+                              keyfile,
+                              encPrivateKey, ntohs (encPrivateKey->len),
+                              "600");
+      GNUNET_RSA_free_key (privKey);
+      GNUNET_GE_LOG (ectx,
+                     GNUNET_GE_INFO | GNUNET_GE_USER | GNUNET_GE_BULK,
+                     _("Done creating key.\n"));
+    }
+  GNUNET_free (keyfile);
+  GNUNET_GE_ASSERT (ectx, encPrivateKey != NULL);
+  return encPrivateKey;
+}
+
+/**
+ * Join a chat room.
+ *
+ * @param nick_name nickname of the user joining (used to
+ *                  determine which public key to use);
+ *                  the nickname should probably also
+ *                  be used in the member_info (as "EXTRACTOR_TITLE")
+ * @param member_info information about the joining member
+ * @param memberInfo public information about you
+ * @param messageCallback which function to call if a message has
+ *        been received?
+ * @param message_cls argument to callback
+ * @param memberCallback which function to call for join/leave notifications
+ * @param confirmationCallback which function to call for confirmations (maybe 
NULL)
+ * @return NULL on error
+ */
+struct GNUNET_CHAT_Room *
+GNUNET_CHAT_join_room (struct GNUNET_GE_Context *ectx,
+                       struct GNUNET_GC_Configuration *cfg,
+                       const char *nick_name,
+                       struct GNUNET_ECRS_MetaData *member_info,
+                       const char *room_name,
+                       GNUNET_CHAT_MessageCallback messageCallback,
+                       void *message_cls,
+                       GNUNET_CHAT_MemberListCallback memberCallback,
+                       void *member_cls,
+                       GNUNET_CHAT_MessageConfirmation confirmationCallback,
+                       void *confirmation_cls)
+{
+  struct GNUNET_CHAT_Room *chat_room;
+  struct GNUNET_ClientServerConnection *sock;
+  GNUNET_RSA_PrivateKeyEncoded *key;
+
+  key = GNUNET_CHAT_initPrivateKey (ectx, cfg, nick_name);
+  if (key == NULL)
+    return NULL;
+  sock = GNUNET_client_connection_create (ectx, cfg);
+  if (sock == NULL)
+    {
+      GNUNET_free (key);
+      return NULL;
+    }
+  chat_room = GNUNET_malloc (sizeof (struct GNUNET_CHAT_Room));
+  chat_room->room_name = GNUNET_strdup (room_name);
+  chat_room->member_info = GNUNET_ECRS_meta_data_duplicate (member_info);
+  chat_room->my_private_key = key;
+  chat_room->message_callback = messageCallback;
+  chat_room->message_callback_cls = message_cls;
+  chat_room->member_list_callback = memberCallback;
+  chat_room->member_list_callback_cls = member_cls;
+  chat_room->confirmation_callback = confirmationCallback;
+  chat_room->confirmation_cls = confirmation_cls;
+  chat_room->ectx = ectx;
+  chat_room->cfg = cfg;
+  chat_room->sock = sock;
+  chat_room->listen_thread =
+    GNUNET_thread_create (&poll_thread, chat_room, 1024 * 2);
+  if (chat_room->listen_thread == NULL)
+    {
+      GNUNET_free (chat_room->room_name);
+      GNUNET_client_connection_destroy (chat_room->sock);
+      GNUNET_ECRS_meta_data_destroy (chat_room->member_info);
+      GNUNET_free (chat_room);
+      GNUNET_free (key);
+      return NULL;
+    }
+  if (GNUNET_SYSERR == GNUNET_CHAT_rejoin_room (chat_room))
+    {
+      GNUNET_CHAT_leave_room (chat_room);
+      return NULL;
+    }
+  return chat_room;
+}
+
+/**
+ * Leave a chat room.
+ */
+void
+GNUNET_CHAT_leave_room (struct GNUNET_CHAT_Room *chat_room)
+{
+  void *unused;
+
+  chat_room->shutdown_flag = GNUNET_YES;
+  GNUNET_client_connection_close_forever (chat_room->sock);
+  GNUNET_thread_stop_sleep (chat_room->listen_thread);
+  GNUNET_thread_join (chat_room->listen_thread, &unused);
+  GNUNET_free (chat_room->room_name);
+  GNUNET_ECRS_meta_data_destroy (chat_room->member_info);
+  GNUNET_client_connection_destroy (chat_room->sock);
+  GNUNET_free (chat_room->my_private_key);
+  GNUNET_free (chat_room);
+}
+
+/**
+ * Send a message.
+ *
+ * @param receiver use NULL to send to everyone in the room
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+int
+GNUNET_CHAT_send_message (struct GNUNET_CHAT_Room *room,
+                          const char *message,
+                          GNUNET_CHAT_MSG_OPTIONS options,
+                          const GNUNET_RSA_PublicKey * receiver,
+                          unsigned int *sequence_number)
+{
+  int ret = GNUNET_OK;
+  CS_chat_MESSAGE_TransmitRequest *msg_to_send;
+  unsigned int msg_size;
+
+  msg_size = strlen (message) + sizeof (CS_chat_MESSAGE_TransmitRequest);
+  if (msg_size > GNUNET_MAX_BUFFER_SIZE - 8)
+    return GNUNET_SYSERR;
+  msg_to_send = GNUNET_malloc (msg_size);
+  msg_to_send->header.size = htons (msg_size);
+  msg_to_send->header.type = htons (GNUNET_CS_PROTO_CHAT_TRANSMIT_REQUEST);
+  msg_to_send->msg_options = htonl (options);
+  *sequence_number = room->sequence_number++;
+  msg_to_send->sequence_number = htonl (*sequence_number);
+  msg_to_send->reserved = htonl (0);
+  if (receiver == NULL)
+    memset (&msg_to_send->target, 0, sizeof (GNUNET_HashCode));
+  else
+    GNUNET_hash (receiver,
+                 sizeof (GNUNET_RSA_PublicKey), &msg_to_send->target);
+  memcpy (&msg_to_send[1], message, strlen (message));
+  ret = GNUNET_client_connection_write (room->sock, &msg_to_send->header);
+  GNUNET_free (msg_to_send);
+  return ret;
+}
+
+/* end of clientapi.c */

Modified: GNUnet/src/applications/chat/module/Makefile.am
===================================================================
--- GNUnet/src/applications/chat/module/Makefile.am     2008-05-31 19:24:20 UTC 
(rev 6944)
+++ GNUnet/src/applications/chat/module/Makefile.am     2008-05-31 19:28:26 UTC 
(rev 6945)
@@ -8,41 +8,10 @@
 plugin_LTLIBRARIES = \
   libgnunetmodule_chat.la
 
-lib_LTLIBRARIES = \
-  libgnunetchat_api.la
-
-bin_PROGRAMS = \
- gnunet-chat
-
-gnunet_chat_SOURCES = \
- gnunet-chat.c         
-gnunet_chat_LDADD = \
-  $(top_builddir)/src/applications/chat/libgnunetchat_api.la 
-
-libgnunetchat_api_la_SOURCES = \
-  clientapi.c 
-libgnunetchat_api_la_LIBADD = \
-  $(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
-  $(top_builddir)/src/util/libgnunetutil.la 
-
 libgnunetmodule_chat_la_SOURCES = \
-  chat.c chat.h
+  chat.c 
 libgnunetmodule_chat_la_LIBADD = \
   $(top_builddir)/src/util/libgnunetutil.la
 libgnunetmodule_chat_la_LDFLAGS = \
   -export-dynamic -avoid-version -module
 
-
-
-check_PROGRAMS = \
-  chattest
-
-TESTS = $(check_PROGRAMS)
-
-chattest_SOURCES = \
-  chattest.c 
-chattest_LDADD = \
-  $(top_builddir)/src/applications/testing/libgnunettesting_api.la \
-  $(top_builddir)/src/applications/stats/libgnunetstats_api.la \
-  $(top_builddir)/src/applications/chat/libgnunetchat_api.la \
-  $(top_builddir)/src/util/libgnunetutil.la 

Copied: GNUnet/src/applications/chat/module/chat.c (from rev 6944, 
GNUnet/src/applications/chat/chat.c)
===================================================================
--- GNUnet/src/applications/chat/module/chat.c                          (rev 0)
+++ GNUnet/src/applications/chat/module/chat.c  2008-05-31 19:28:26 UTC (rev 
6945)
@@ -0,0 +1,316 @@
+/*
+     This file is part of GNUnet.
+     (C) 2008 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * CHAT CORE. This is the code that is plugged
+ * into the GNUnet core to enable chatting.
+ *
+ * @author Christian Grothoff
+ * @author Nathan Evans
+ * @file applications/chat/chat.c
+ */
+
+#include "platform.h"
+#include "gnunet_protocols.h"
+#include "gnunet_util.h"
+#include "gnunet_core.h"
+#include "chat.h"
+
+/**
+ * Linked list of our current clients.
+ */
+struct GNUNET_CS_chat_client
+{
+  struct GNUNET_CS_chat_client *next;
+
+  struct GNUNET_ClientHandle *client;
+
+  struct GNUNET_RSA_PrivateKey *private_key;
+
+  char *room;
+
+  /**
+   * Hash of the public key (for convenience).
+   */
+  GNUNET_HashCode id;
+
+  unsigned int msg_options;
+
+};
+
+static struct GNUNET_CS_chat_client *client_list_head;
+
+static GNUNET_CoreAPIForPlugins *coreAPI;
+
+static struct GNUNET_Mutex *chatMutex;
+
+static int
+csHandleTransmitRequest (struct GNUNET_ClientHandle *client,
+                         const GNUNET_MessageHeader * message)
+{
+  static GNUNET_HashCode all_zeros;
+  const CS_chat_MESSAGE_TransmitRequest *cmsg;
+  CS_chat_MESSAGE_ReceiveNotification *rmsg;
+  CS_chat_MESSAGE_ConfirmationReceipt receipt;
+  struct GNUNET_CS_chat_client *pos;
+  const char *room;
+  unsigned int msg_len;
+  int priv_msg;
+
+  if (ntohs (message->size) < sizeof (CS_chat_MESSAGE_TransmitRequest))
+    {
+      GNUNET_GE_BREAK (NULL, 0);
+      return GNUNET_SYSERR;     /* invalid message */
+    }
+  cmsg = (const CS_chat_MESSAGE_TransmitRequest *) message;
+  msg_len = ntohs (message->size) - sizeof (CS_chat_MESSAGE_TransmitRequest);
+  rmsg = GNUNET_malloc (sizeof (CS_chat_MESSAGE_ReceiveNotification) +
+                        msg_len);
+  rmsg->header.size = htons (sizeof (CS_chat_MESSAGE_ReceiveNotification) +
+                             msg_len);
+  rmsg->header.type = htons (GNUNET_CS_PROTO_CHAT_MESSAGE_NOTIFICATION);
+  rmsg->msg_options = cmsg->msg_options;
+  GNUNET_mutex_lock (chatMutex);
+
+  pos = client_list_head;
+  while ((pos != NULL) && (pos->client != client))
+    pos = pos->next;
+  if (pos == NULL)
+    {
+      GNUNET_mutex_unlock (chatMutex);
+      GNUNET_GE_BREAK (NULL, 0);
+      GNUNET_free (rmsg);
+      return GNUNET_SYSERR;     /* not member of chat room! */
+    }
+  room = pos->room;
+  if ((ntohl (cmsg->msg_options) & GNUNET_CHAT_MSG_ANONYMOUS) == 0)
+    rmsg->sender = pos->id;
+  else
+    memset (&rmsg->sender, 0, sizeof (GNUNET_HashCode));
+  priv_msg = (0 == memcmp(&all_zeros,
+                         &cmsg->target,
+                         sizeof(GNUNET_HashCode)));
+  memcpy(&rmsg[1],
+        &cmsg[1],
+        msg_len);
+  pos = client_list_head;
+  while (pos != NULL)
+    {
+      if (0 == strcmp (room, pos->room))
+        {
+         if ( ( (!priv_msg) ||
+                (0 == memcmp(&cmsg->target,
+                             &pos->id,
+                             sizeof(GNUNET_HashCode))) ) &&
+              ( (0 == ntohl(cmsg->msg_options)) & (~pos->msg_options) ) )
+           {
+             coreAPI->cs_send_message (pos->client, &rmsg->header, GNUNET_YES);
+             if (0 != (ntohl(cmsg->msg_options)&GNUNET_CHAT_MSG_ACKNOWLEDGED))
+               {
+                 receipt.header.size = 
htons(sizeof(CS_chat_MESSAGE_ConfirmationReceipt));
+                 receipt.header.type = 
htons(GNUNET_CS_PROTO_CHAT_CONFIRMATION_RECEIPT);
+                 receipt.sequence_number = cmsg->sequence_number;
+                 receipt.timestamp = GNUNET_htonll(GNUNET_get_time());
+                 receipt.target = pos->id;
+                 /* FIXME: this will currently *always* be the plaintext 
message;
+                    once we have P2P, we want to sign the encrypted message
+                    (which we currently do not even generate!) */
+                 GNUNET_hash(&cmsg[1],
+                             msg_len,
+                             &receipt.content);
+                 GNUNET_RSA_sign(pos->private_key,
+                                 sizeof(CS_chat_MESSAGE_ConfirmationReceipt) - 
sizeof(GNUNET_RSA_Signature),
+                                 &receipt,
+                                 &receipt.signature);            
+                 coreAPI->cs_send_message (client, &receipt.header, 
GNUNET_YES);
+               }
+           }
+        }
+      pos = pos->next;
+    }
+  GNUNET_mutex_unlock (chatMutex);
+  GNUNET_free (rmsg);
+  return GNUNET_OK;
+}
+
+static int
+csHandleChatJoinRequest (struct GNUNET_ClientHandle *client,
+                         const GNUNET_MessageHeader * message)
+{
+  const CS_chat_MESSAGE_JoinRequest *cmsg;
+  char *room_name;
+  const char *roomptr;
+  unsigned int header_size;
+  unsigned int meta_len;
+  unsigned int room_name_len;
+  struct GNUNET_CS_chat_client *entry;
+  GNUNET_RSA_PublicKey pkey;
+  CS_chat_MESSAGE_JoinNotification *nmsg;
+
+  if (ntohs (message->size) < sizeof (CS_chat_MESSAGE_JoinRequest))
+    {
+      GNUNET_GE_BREAK (NULL, 0);
+      return GNUNET_SYSERR;     /* invalid message */
+    }
+  cmsg = (const CS_chat_MESSAGE_JoinRequest *) message;
+  header_size = ntohs (cmsg->header.size);
+  room_name_len = ntohs (cmsg->room_name_len);
+  if (header_size - sizeof (CS_chat_MESSAGE_JoinRequest) <= room_name_len)
+    {
+      GNUNET_GE_BREAK (NULL, 0);
+      return GNUNET_SYSERR;
+    }
+  meta_len =
+    header_size - sizeof (CS_chat_MESSAGE_JoinRequest) - room_name_len;
+
+  roomptr = (const char *) &cmsg[1];
+  room_name = GNUNET_malloc (room_name_len + 1);
+  memcpy (room_name, roomptr, room_name_len);
+  room_name[room_name_len] = '\0';
+
+  entry = GNUNET_malloc (sizeof (struct GNUNET_CS_chat_client));
+  memset (entry, 0, sizeof (struct GNUNET_CS_chat_client));
+  entry->client = client;
+  entry->room = room_name;
+  entry->private_key = GNUNET_RSA_decode_key (&cmsg->private_key);
+  if (entry->private_key == NULL)
+    {
+      GNUNET_GE_BREAK (NULL, 0);
+      GNUNET_free (room_name);
+      GNUNET_free (entry);
+      return GNUNET_SYSERR;
+    }
+  GNUNET_RSA_get_public_key (entry->private_key, &pkey);
+  GNUNET_hash (&pkey, sizeof (GNUNET_RSA_PublicKey), &entry->id);
+  entry->msg_options = ntohl (cmsg->msg_options);
+
+
+  nmsg = GNUNET_malloc (sizeof (CS_chat_MESSAGE_JoinNotification) + meta_len);
+  nmsg->header.type = htons (GNUNET_CS_PROTO_CHAT_JOIN_NOTIFICATION);
+  nmsg->header.size =
+    htons (sizeof (CS_chat_MESSAGE_JoinNotification) + meta_len);
+  nmsg->msg_options = cmsg->msg_options;
+  nmsg->public_key = pkey;
+  memcpy (&nmsg[1], &roomptr[room_name_len], meta_len);
+  GNUNET_mutex_lock (chatMutex);
+  entry->next = client_list_head;
+  client_list_head = entry;
+  while (entry != NULL)
+    {
+      if (0 == strcmp (room_name, entry->room))
+        coreAPI->cs_send_message (entry->client, &nmsg->header, GNUNET_YES);
+      entry = entry->next;
+    }
+  GNUNET_mutex_unlock (chatMutex);
+  GNUNET_free (nmsg);
+  return GNUNET_OK;
+}
+
+static void
+chatClientExitHandler (struct GNUNET_ClientHandle *client)
+{
+  struct GNUNET_CS_chat_client *entry;
+  struct GNUNET_CS_chat_client *pos;
+  struct GNUNET_CS_chat_client *prev;
+  CS_chat_MESSAGE_LeaveNotification lmsg;
+
+  GNUNET_mutex_lock (chatMutex);
+  pos = client_list_head;
+  prev = NULL;
+  while ((pos != NULL) && (pos->client != client))
+    {
+      prev = pos;
+      pos = pos->next;
+    }
+  if (pos == NULL)
+    {
+      GNUNET_mutex_unlock (chatMutex);
+      return;                   /* nothing to do */
+    }
+  if (prev == NULL)
+    client_list_head = pos->next;
+  else
+    prev->next = pos->next;
+  entry = client_list_head;
+  lmsg.header.size = htons (sizeof (CS_chat_MESSAGE_LeaveNotification));
+  lmsg.header.type = htons (GNUNET_CS_PROTO_CHAT_LEAVE_NOTIFICATION);
+  lmsg.reserved = htonl (0);
+  GNUNET_RSA_get_public_key (pos->private_key, &lmsg.user);
+  while (entry != NULL)
+    {
+      if (0 == strcmp (entry->room, pos->room))
+        coreAPI->cs_send_message (entry->client, &lmsg.header, GNUNET_YES);
+      entry = entry->next;
+    }
+  GNUNET_mutex_unlock (chatMutex);
+  GNUNET_free (pos->room);
+  GNUNET_RSA_free_key (pos->private_key);
+  GNUNET_free (pos);
+}
+
+int
+initialize_module_chat (GNUNET_CoreAPIForPlugins * capi)
+{
+  int ok = GNUNET_OK;
+
+  coreAPI = capi;
+  GNUNET_GE_LOG (capi->ectx,
+                 GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
+                 _("`%s' registering CS handlers %d and %d\n"),
+                 "chat",
+                 GNUNET_CS_PROTO_CHAT_JOIN_REQUEST,
+                 GNUNET_CS_PROTO_CHAT_TRANSMIT_REQUEST);
+
+  if (GNUNET_SYSERR ==
+      capi->cs_disconnect_handler_register (&chatClientExitHandler))
+    ok = GNUNET_SYSERR;
+  if (GNUNET_SYSERR ==
+      capi->cs_handler_register (GNUNET_CS_PROTO_CHAT_JOIN_REQUEST,
+                                 &csHandleChatJoinRequest))
+    ok = GNUNET_SYSERR;
+  if (GNUNET_SYSERR ==
+      capi->cs_handler_register (GNUNET_CS_PROTO_CHAT_TRANSMIT_REQUEST,
+                                 &csHandleTransmitRequest))
+    ok = GNUNET_SYSERR;
+  GNUNET_GE_ASSERT (capi->ectx,
+                    0 == GNUNET_GC_set_configuration_value_string (capi->cfg,
+                                                                   capi->ectx,
+                                                                   "ABOUT",
+                                                                   "chat",
+                                                                   _
+                                                                   ("enables 
P2P-chat (incomplete)")));
+  chatMutex = GNUNET_mutex_create (GNUNET_NO);
+  return ok;
+}
+
+void
+done_module_chat ()
+{
+  coreAPI->cs_disconnect_handler_unregister (&chatClientExitHandler);
+  coreAPI->cs_handler_unregister (GNUNET_CS_PROTO_CHAT_TRANSMIT_REQUEST,
+                                  &csHandleTransmitRequest);
+  coreAPI->cs_handler_unregister (GNUNET_CS_PROTO_CHAT_JOIN_REQUEST,
+                                  &csHandleChatJoinRequest);
+  GNUNET_mutex_destroy (chatMutex);
+  coreAPI = NULL;
+}
+
+
+/* end of chat.c */

Copied: GNUnet/src/applications/chat/module/p2p.c (from rev 6943, 
GNUnet/src/applications/chat/chat_p2p.c)
===================================================================
--- GNUnet/src/applications/chat/module/p2p.c                           (rev 0)
+++ GNUnet/src/applications/chat/module/p2p.c   2008-05-31 19:28:26 UTC (rev 
6945)
@@ -0,0 +1,57 @@
+/*
+     This file is part of GNUnet.
+     (C) 2008 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @author Nathan Evans
+ * @file applications/chat/chat_p2p.c
+ */
+#include "chat_p2p.h"
+
+int
+p2pHandleChatJoinRequest (struct GNUNET_ClientHandle *client,
+                          const GNUNET_MessageHeader * message)
+{
+  return GNUNET_SYSERR;
+}
+
+int
+p2pHandleChatMSG (struct GNUNET_ClientHandle *client,
+                  const GNUNET_MessageHeader * message)
+{
+  return GNUNET_SYSERR;
+}
+
+int
+p2pSendChatMSG (const GNUNET_MessageHeader * message)
+{
+  return GNUNET_SYSERR;
+}
+
+int
+p2pGetRoomList ()
+{
+  return GNUNET_SYSERR;
+}
+
+int
+p2pSendRoomList ()
+{
+  return GNUNET_SYSERR;
+}

Copied: GNUnet/src/applications/chat/module/p2p.h (from rev 6943, 
GNUnet/src/applications/chat/chat_p2p.h)
===================================================================
--- GNUnet/src/applications/chat/module/p2p.h                           (rev 0)
+++ GNUnet/src/applications/chat/module/p2p.h   2008-05-31 19:28:26 UTC (rev 
6945)
@@ -0,0 +1,58 @@
+/*
+     This file is part of GNUnet.
+     (C) 2008 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @author Nathan Evans
+ * @file applications/chat/chat_p2p.h
+ *
+ * TODO:
+ * - change all GNUNET_MessageHandler arguments
+ *   to the specific interesting values (chat_p2p.c
+ *   should not have to parse them again -- chat.c already did!);
+ *   Also, that way, this API becomes independent of
+ *   changes to the CS-protocol!
+ * - define callbacks for how the P2P code will notify CS
+ *   about new messages / users joining the room, etc.
+ * - instead of passing the ClientHandle, pass something useful
+ *   like the private RSA key or so.
+ *
+ */
+#ifndef CHATP2P_H
+#define CHATP2P_H
+
+#include "chat.h"
+
+int
+p2pHandleChatJoinRequest (struct GNUNET_ClientHandle *client,
+                          const GNUNET_MessageHeader * message);
+
+int
+p2pHandleChatMSG (struct GNUNET_ClientHandle *client,
+                  const GNUNET_MessageHeader * message);
+
+int p2pSendChatMSG (const GNUNET_MessageHeader * message);
+
+int p2pGetRoomList (void);
+
+int p2pSendRoomList (void);
+
+#endif
+
+/* end of chat_p2p.h */

Modified: GNUnet/src/applications/chat/tools/Makefile.am
===================================================================
--- GNUnet/src/applications/chat/tools/Makefile.am      2008-05-31 19:24:20 UTC 
(rev 6944)
+++ GNUnet/src/applications/chat/tools/Makefile.am      2008-05-31 19:28:26 UTC 
(rev 6945)
@@ -3,46 +3,11 @@
 LDADD = \
  $(top_builddir)/src/util/libgnunetutil.la 
 
-plugindir = $(libdir)/GNUnet
-
-plugin_LTLIBRARIES = \
-  libgnunetmodule_chat.la
-
-lib_LTLIBRARIES = \
-  libgnunetchat_api.la
-
 bin_PROGRAMS = \
  gnunet-chat
 
 gnunet_chat_SOURCES = \
  gnunet-chat.c         
 gnunet_chat_LDADD = \
-  $(top_builddir)/src/applications/chat/libgnunetchat_api.la 
+  $(top_builddir)/src/applications/chat/lib/libgnunetchat_api.la 
 
-libgnunetchat_api_la_SOURCES = \
-  clientapi.c 
-libgnunetchat_api_la_LIBADD = \
-  $(top_builddir)/src/applications/fs/ecrs/libgnunetecrs.la \
-  $(top_builddir)/src/util/libgnunetutil.la 
-
-libgnunetmodule_chat_la_SOURCES = \
-  chat.c chat.h
-libgnunetmodule_chat_la_LIBADD = \
-  $(top_builddir)/src/util/libgnunetutil.la
-libgnunetmodule_chat_la_LDFLAGS = \
-  -export-dynamic -avoid-version -module
-
-
-
-check_PROGRAMS = \
-  chattest
-
-TESTS = $(check_PROGRAMS)
-
-chattest_SOURCES = \
-  chattest.c 
-chattest_LDADD = \
-  $(top_builddir)/src/applications/testing/libgnunettesting_api.la \
-  $(top_builddir)/src/applications/stats/libgnunetstats_api.la \
-  $(top_builddir)/src/applications/chat/libgnunetchat_api.la \
-  $(top_builddir)/src/util/libgnunetutil.la 

Copied: GNUnet/src/applications/chat/tools/gnunet-chat.c (from rev 6943, 
GNUnet/src/applications/chat/gnunet-chat.c)
===================================================================
--- GNUnet/src/applications/chat/tools/gnunet-chat.c                            
(rev 0)
+++ GNUnet/src/applications/chat/tools/gnunet-chat.c    2008-05-31 19:28:26 UTC 
(rev 6945)
@@ -0,0 +1,200 @@
+/*
+     This file is part of GNUnet.
+     (C) 2007, 2008 Christian Grothoff (and other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file applications/chat/gnunet-chat.c
+ * @brief Minimal chat command line tool
+ * @author Christian Grothoff
+ * @author Nathan Evans
+ */
+
+#include "platform.h"
+#include "gnunet_protocols.h"
+#include "gnunet_directories.h"
+#include "gnunet_chat_lib.h"
+#include "gnunet_ecrs_lib.h"
+
+#define MAX_MESSAGE_LENGTH 1024
+
+#define QUIT_COMMAND "quit"
+
+static struct GNUNET_GC_Configuration *cfg;
+
+static struct GNUNET_GE_Context *ectx;
+
+static char *cfgFilename = GNUNET_DEFAULT_CLIENT_CONFIG_FILE;
+
+static char *nickname;
+
+static char *room_name = "gnunet";
+
+/**
+ * All gnunet-chat command line options
+ */
+static struct GNUNET_CommandLineOption gnunetchatOptions[] = {
+  GNUNET_COMMAND_LINE_OPTION_HELP (gettext_noop ("Join a chat on GNUnet.")),   
 /* -h */
+  GNUNET_COMMAND_LINE_OPTION_HOSTNAME,  /* -H */
+  GNUNET_COMMAND_LINE_OPTION_LOGGING,   /* -L */
+  {'n', "nick", "NAME",
+   gettext_noop ("set the nickname to use (required)"),
+   1, &GNUNET_getopt_configure_set_string, &nickname},
+  {'r', "room", "NAME",
+   gettext_noop ("set the chat room to join"),
+   1, &GNUNET_getopt_configure_set_string, &room_name},
+  GNUNET_COMMAND_LINE_OPTION_VERSION (PACKAGE_VERSION), /* -v */
+  GNUNET_COMMAND_LINE_OPTION_VERBOSE,
+  GNUNET_COMMAND_LINE_OPTION_END,
+};
+
+/**
+ * A message was sent in the chat to us.
+ *
+ * @param timestamp when was the message sent?
+ * @param senderNick what is the nickname of the sender? (maybe NULL)
+ * @param message the message (maybe NULL, especially if confirmation
+ *        is requested before delivery; the protocol will ensure
+ *        that this function is called again with the full message
+ *        if a confirmation is transmitted; if the message is NULL,
+ *        the user is merely asked if engaging in the exchange is ok
+ * @param room in which room was the message received?
+ * @param options options for the message
+ * @return GNUNET_OK to accept the message now, GNUNET_NO to
+ *         accept (but user is away), GNUNET_SYSERR to signal denied delivery
+ */
+static int
+receive_callback (void *cls,
+                  struct GNUNET_CHAT_Room *room,
+                  const GNUNET_HashCode * sender,
+                  const char *message, GNUNET_CHAT_MSG_OPTIONS options)
+{
+  fprintf (stdout, _("`%s' said: %s\n"), "FIXME", message);
+  return GNUNET_OK;
+}
+
+static int
+member_list_callback (void *cls,
+                      const struct GNUNET_ECRS_MetaData *member_info,
+                      const GNUNET_RSA_PublicKey * member_id)
+{
+  fprintf (stdout, member_info != NULL
+           ? _("`%s' entered the room\n")
+           : _("`%s' left the room\n"), "FIXME");
+  return GNUNET_OK;
+}
+
+/**
+ * Message delivery confirmations.
+ *
+ * @param timestamp when was the message received?
+ * @param message the message (maybe NULL)
+ * @param room in which room was the message received?
+ * @param receipt signature confirming delivery (maybe NULL, only
+ *        if confirmation was requested)
+ * @return GNUNET_OK to continue, GNUNET_SYSERR to refuse processing further
+ *         confirmations from anyone for this message
+ */
+static int
+confirmation_callback (void *cls,
+                       struct GNUNET_CHAT_Room *room,
+                       unsigned int orig_seq_number,
+                       GNUNET_CronTime timestamp,
+                       const GNUNET_HashCode * receiver,
+                       const GNUNET_HashCode * msg_hash,
+                       const GNUNET_RSA_Signature * receipt)
+{
+  return GNUNET_OK;
+}
+
+/**
+ * GNUnet-chat main.
+ *
+ * @param argc number of arguments from the command line
+ * @param argv command line arguments
+ * @return  0: ok, otherwise error
+ */
+int
+main (int argc, char **argv)
+{
+  struct GNUNET_CHAT_Room *room;
+  struct GNUNET_RSA_PrivateKey *my_priv;
+  struct GNUNET_ECRS_MetaData *meta;
+  char message[MAX_MESSAGE_LENGTH + 1];
+  unsigned int seq;
+
+  if (GNUNET_SYSERR == GNUNET_init (argc,
+                                    argv,
+                                    "gnunet-chat [OPTIONS]",
+                                    &cfgFilename, gnunetchatOptions, &ectx,
+                                    &cfg))
+    return -1;
+  if (nickname == NULL)
+    {
+      fprintf (stderr, _("You must specify a nickname\n"));
+      GNUNET_fini (ectx, cfg);
+      return -1;
+    }
+
+  meta = GNUNET_ECRS_meta_data_create ();
+  GNUNET_ECRS_meta_data_insert (meta, EXTRACTOR_TITLE, nickname);
+  room = GNUNET_CHAT_join_room (ectx,
+                                cfg,
+                                nickname,
+                                meta,
+                                room_name,
+                                &receive_callback,
+                                NULL, &member_list_callback, NULL,
+                                &confirmation_callback, NULL);
+  GNUNET_ECRS_meta_data_destroy (meta);
+  if (room == NULL)
+    {
+      fprintf (stderr, _("Failed to join room `%s'\n"), room_name);
+      GNUNET_RSA_free_key (my_priv);
+      GNUNET_fini (ectx, cfg);
+      return -1;
+    }
+  fprintf (stdout,
+           _
+           ("Joined room `%s'.\nType message and hit return to send.\nType 
`%s' when ready to quit.\n"),
+           room_name, QUIT_COMMAND);
+  /* read messages from command line and send */
+  while ((0 != strcmp (message, QUIT_COMMAND)) &&
+         (GNUNET_shutdown_test () == GNUNET_NO))
+    {
+      memset (message, 0, MAX_MESSAGE_LENGTH + 1);
+      if (NULL == fgets (message, MAX_MESSAGE_LENGTH, stdin))
+        break;
+      if (0 == strcmp (message, QUIT_COMMAND))
+        break;
+      if (message[strlen (message) - 1] == '\n')
+        message[strlen (message) - 1] = '\0';
+      if (GNUNET_OK != GNUNET_CHAT_send_message (room,
+                                                 message,
+                                                 GNUNET_CHAT_MSG_OPTION_NONE,
+                                                 NULL, &seq))
+        fprintf (stderr, _("Failed to send message.\n"));
+    }
+
+  GNUNET_CHAT_leave_room (room);
+  GNUNET_RSA_free_key (my_priv);
+  GNUNET_fini (ectx, cfg);
+  return 0;
+}
+
+/* end of gnunet-chat.c */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]