Index: plugins/roard/protocol-esound.c
===================================================================
--- plugins/roard/protocol-esound.c	(revision 5640)
+++ plugins/roard/protocol-esound.c	(revision 5739)
@@ -28,4 +28,40 @@
 #ifndef ROAR_WITHOUT_DCOMP_EMUL_ESD
 #ifdef ROAR_HAVE_H_ESD
+#include <esd.h>
+
+
+struct emul_esd_command {
+ int    cmd;
+ size_t datalen;
+#if !defined(ROAR_TARGET_MICROCONTROLLER) && !defined(ROAR_MINIMAL)
+ char name[COMMAND_MAX_NAMELEN];
+#else
+ char * name;
+#endif
+ int (*handler)(int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio);
+};
+
+static int emul_esd_exec_command  (int client, int cmd, struct roar_vio_calls * vio);
+static int emul_esd_check_client  (int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara);
+
+static int emul_esd_int_read_buf  (int client, int * data, void * buf);
+static int emul_esd_int_read      (int client, int * data, struct roar_vio_calls * vio);
+static int emul_esd_int_write     (int client, int   data, struct roar_vio_calls * vio);
+static int emul_esd_test_auth     (int client, void * data, struct roar_vio_calls * vio);
+static int emul_esd_test_byteorder(int client, void * data);
+
+static int emul_esd_on_connect    (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio);
+static int emul_esd_on_stream     (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio);
+static int emul_esd_on_latency    (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio);
+static int emul_esd_on_standby    (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio);
+static int emul_esd_on_standbymode(int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio);
+
+static int emul_esd_on_stream_pan (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio);
+
+static int emul_esd_on_server_info(int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio);
+
+static int emul_esd_on_all_info   (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio);
+
+
 
 #if !defined(ROAR_TARGET_MICROCONTROLLER) && !defined(ROAR_MINIMAL)
@@ -45,5 +81,5 @@
 #define _ESD2ROAR(x) ((x)-1)
 
-struct emul_esd_command g_emul_esd_commands[] = {
+static struct emul_esd_command g_emul_esd_commands[] = {
  {ESD_PROTO_CONNECT,      ESD_KEY_LEN  +     _INTSIZE, _NAME("CONNECT"),      emul_esd_on_connect},
  {ESD_PROTO_LOCK,         ESD_KEY_LEN  +     _INTSIZE, _NAME("LOCK"),         NULL},
@@ -75,5 +111,5 @@
 
 // command handling:
-int emul_esd_exec_command(int client, int cmd, struct roar_vio_calls * vio) {
+static int emul_esd_exec_command(int client, int cmd, struct roar_vio_calls * vio) {
  struct emul_esd_command * cur;
  void * data = NULL;
@@ -95,5 +131,4 @@
     if ( (data = roar_mm_malloc(cur->datalen)) == NULL ) {
      // we will do a protocol error in case we do not drop the client
-     clients_delete(client);
      return -1;
     }
@@ -104,5 +139,4 @@
      if ( ret < 1 ) {
       roar_mm_free(data);
-      clients_delete(client);
       return -1;
      } else {
@@ -116,5 +150,4 @@
                client, cur->name, cmd, vio
              );
-    clients_delete(client);
     r = -1;
    } else {
@@ -132,20 +165,19 @@
 }
 
-int emul_esd_check_client(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara) {
- struct roar_vio_calls calls;
+static int emul_esd_set_proto(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara) {
+ if ( emul_esd_exec_command(client, ESD_PROTO_CONNECT, vio) == -1 )
+  return -1;
+
+ return 0;
+}
+
+static int emul_esd_check_client(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara) {
  _cmd_t cmd;
 
  if ( client == -1 )
   return -1;
-
- if ( vio == NULL ) {
-  vio = &calls;
-  if ( roar_vio_open_fh_socket(vio, clients_get_fh(client)) == -1 )
-   return -1;
- }
 
  if ( roar_vio_read(vio, &cmd, _INTSIZE) != _INTSIZE ) {
   // really bad protocol error
-  clients_delete(client);
   return -1;
  }
@@ -167,5 +199,5 @@
  return 0;
 }
-int emul_esd_int_read      (int client, int * data, struct roar_vio_calls * vio) {
+static int emul_esd_int_read      (int client, int * data, struct roar_vio_calls * vio) {
  _cmd_t d;
 
@@ -181,5 +213,5 @@
 }
 
-int emul_esd_int_write     (int client, int   data, struct roar_vio_calls * vio) {
+static int emul_esd_int_write     (int client, int   data, struct roar_vio_calls * vio) {
  _cmd_t d = data;
 
@@ -187,10 +219,10 @@
 }
 
-int emul_esd_test_auth     (int client, void * data, struct roar_vio_calls * vio) {
+static int emul_esd_test_auth     (int client, void * data, struct roar_vio_calls * vio) {
  // accept all clients for the moment.
  return emul_esd_int_write(client, 1, vio);
 }
 
-int emul_esd_test_byteorder(int client, void * data) {
+static int emul_esd_test_byteorder(int client, void * data) {
  struct roar_client * c;
 
@@ -214,5 +246,5 @@
 
 // handler:
-int emul_esd_on_connect    (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) {
+static int emul_esd_on_connect    (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) {
 
  ROAR_DBG("emul_esd_on_connect(client=%i, cmd=%p, data=%p, vio=%p) = ?", client, cmd, data, vio);
@@ -236,5 +268,5 @@
 }
 
-int emul_esd_on_stream     (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) {
+static int emul_esd_on_stream     (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) {
  struct roar_stream_server * ss;
  struct roar_stream        *  s;
@@ -254,5 +286,4 @@
   case ESD_PROTO_STREAM_FILT: dir = ROAR_DIR_FILTER;  break;
   default:
-    clients_delete(client);
     return -1;
  }
@@ -264,5 +295,4 @@
  ROAR_DBG("emul_esd_on_stream(client=%i, ...): creating stream...", client);
  if ((stream = streams_new()) == -1 ) {
-  clients_delete(client);
   return -1;
  }
@@ -271,5 +301,4 @@
  if ( streams_get(stream, &ss) == -1 ) {
   streams_delete(stream);
-  clients_delete(client);
   return -1;
  }
@@ -280,5 +309,4 @@
  if ( client_stream_add(client, stream) == -1 ) {
   streams_delete(stream);
-  clients_delete(client);
   return -1;
  }
@@ -299,5 +327,4 @@
   default:
     streams_delete(stream);
-    clients_delete(client);
     return -1;
  }
@@ -308,5 +335,4 @@
   default:
     streams_delete(stream);
-    clients_delete(client);
     return -1;
  }
@@ -317,17 +343,15 @@
 
  if ( streams_set_dir(stream, dir, 1) == -1 ) {
-  clients_delete(client);
   return -1;
  }
 
  if ( client_stream_exec(client, stream) == -1 ) {
-  clients_delete(client);
-  return -1;
- }
-
- return 0;
-}
-
-int emul_esd_on_latency    (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) {
+  return -1;
+ }
+
+ return 0;
+}
+
+static int emul_esd_on_latency    (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) {
  int lag = ROAR_OUTPUT_CFREQ;
 
@@ -337,5 +361,5 @@
 }
 
-int emul_esd_on_standby    (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) {
+static int emul_esd_on_standby    (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) {
  int ok = 0;
 
@@ -356,5 +380,5 @@
 }
 
-int emul_esd_on_standbymode(int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) {
+static int emul_esd_on_standbymode(int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) {
  int mode = ESM_ERROR;
 
@@ -372,5 +396,5 @@
 }
 
-int emul_esd_on_stream_pan (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) {
+static int emul_esd_on_stream_pan (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) {
  struct roar_stream_server * ss;
  int stream = -1;
@@ -395,5 +419,5 @@
 }
 
-int emul_esd_on_server_info(int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) {
+static int emul_esd_on_server_info(int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) {
  int version = 0;
  int rate    = g_sa->rate;
@@ -422,5 +446,5 @@
 }
 
-int emul_esd_on_all_info   (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) {
+static int emul_esd_on_all_info   (int client, struct emul_esd_command * cmd, void * data, struct roar_vio_calls * vio) {
  struct roar_stream_server *   ss;
  struct roar_audio_info    * info;
@@ -532,4 +556,12 @@
 }
 
+struct roar_dl_proto __proto_common_esd = {
+ .proto = ROAR_PROTO_ESOUND,
+ .description = "EsounD emulation",
+ .flags = ROAR_DL_PROTO_FLAGS_NONE,
+ .set_proto = emul_esd_set_proto,
+ .handle = emul_esd_check_client
+};
+
 #endif
 #endif
Index: plugins/roard/protocol-gopher.c
===================================================================
--- plugins/roard/protocol-gopher.c	(revision 5640)
+++ plugins/roard/protocol-gopher.c	(revision 5739)
@@ -631,7 +631,6 @@
 }
 
-int emul_gopher_check_client(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara) {
+static int emul_gopher_check_client(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara) {
  struct roar_client_server * cs;
- struct roar_vio_calls     rvio;
  struct item * c = NULL;
  char inbuf[1024];
@@ -646,14 +645,8 @@
 
  if ( clients_get_server(client, &cs) == -1 ) {
-  clients_delete(client);
   return -1;
  }
 
  ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = ?", client, vio);
-
- if ( vio == NULL ) {
-  vio = &rvio;
-  roar_vio_open_fh_socket(vio, clients_get_fh(client));
- }
 
  ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = ?", client, vio);
@@ -662,5 +655,4 @@
   len = sizeof(inbuf)-1;
   if ( roar_buffer_shift_out(&(cs->inbuf), inbuf, &len) == -1 ) {
-   clients_delete(client);
    return -1;
   }
@@ -668,5 +660,4 @@
   if ( cs->inbuf != NULL ) {
    roar_buffer_free(cs->inbuf);
-   clients_delete(client);
    return -1;
   }
@@ -674,5 +665,4 @@
   // test if we have still buffer space left.
   if ( len == (sizeof(inbuf)-1) ) {
-   clients_delete(client);
    return -1;
   }
@@ -683,5 +673,4 @@
  ret = roar_vio_read(vio, inbuf+len, sizeof(inbuf)-len-1);
  if ( ret < 1 ) {
-  clients_delete(client);
   ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = -1", client, vio);
   return -1;
@@ -696,5 +685,4 @@
  if ( !strip_nl(inbuf) ) {
   if ( roar_buffer_new_data(&(cs->inbuf), ret, &data) == -1 ) {
-   clients_delete(client);
    ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = -1", client, vio);
    return -1;
@@ -719,5 +707,4 @@
 
  if ( c == NULL ) {
-  clients_delete(client);
   ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = -1", client, vio);
   return -1;
@@ -752,5 +739,4 @@
 
  if ( funcret == -1 ) {
-  clients_delete(client);
   ROAR_DBG("emul_gopher_check_client(client=%i, vio=%p) = -1", client, vio);
   return -1;
@@ -762,9 +748,17 @@
 }
 
-int emul_gopher_flushed_client(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara) {
+static int emul_gopher_flushed_client(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara) {
  ROAR_DBG("emul_gopher_flushed_client(client=%i, vio=%p) = ?", client, vio);
 
- return clients_delete(client);
-}
+ return -1;
+}
+
+struct roar_dl_proto __proto_common_gopher = {
+ .proto = ROAR_PROTO_GOPHER,
+ .description = "The Internet Gopher Protocol",
+ .flags = ROAR_DL_PROTO_FLAGS_NONE,
+ .handle = emul_gopher_check_client,
+ .flushed = emul_gopher_flushed_client
+};
 
 #endif
Index: plugins/roard/protocol-rplay.c
===================================================================
--- plugins/roard/protocol-rplay.c	(revision 5640)
+++ plugins/roard/protocol-rplay.c	(revision 5739)
@@ -28,5 +28,30 @@
 #ifndef ROAR_WITHOUT_DCOMP_EMUL_RPLAY
 
-struct emul_rplay_command emul_rplay_commands[] = {
+struct emul_rplay_command {
+ const char * name;
+ const char * usage;
+ ssize_t      min_args;
+ ssize_t      max_args;
+ int (*handler)(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen);
+};
+
+static int emul_rplay_exec_command  (int client, struct roar_vio_calls * vio, char * command);
+
+static int emul_rplay_send_error    (int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen, const char * msg);
+
+static int emul_rplay_on_status(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen);
+static int emul_rplay_on_quit(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen);
+static int emul_rplay_on_help(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen);
+
+// things we need to implent soon:
+static int emul_rplay_on_play(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen);
+static int emul_rplay_on_put(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen);
+//static int emul_rplay_on_set(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen);
+//static int emul_rplay_on_modify(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen);
+static int emul_rplay_on_pause(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen);
+static int emul_rplay_on_continue(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen);
+//static int emul_rplay_on_stop(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen);
+
+static struct emul_rplay_command emul_rplay_commands[] = {
  {"access",      NULL, -1, -1, NULL},
  {"application", NULL,  1, -1, NULL},
@@ -111,6 +136,12 @@
 }
 
-int emul_rplay_check_client  (int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara) {
- struct roar_vio_calls calls;
+static int emul_rplay_set_proto  (int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara) {
+ if ( emul_rplay_on_status(client, NULL, vio, NULL, 0) == -1 )
+  return -1;
+
+ return 0;
+}
+
+static int emul_rplay_check_client  (int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * protopara, ssize_t protoparalen, struct roar_dl_librarypara * pluginpara) {
  char buf[1024];
  ssize_t len;
@@ -119,13 +150,6 @@
   return -1;
 
- if ( vio == NULL ) {
-  vio = &calls;
-  if ( roar_vio_open_fh_socket(vio, clients_get_fh(client)) == -1 )
-   return -1;
- }
-
  if ( (len = roar_vio_read(vio, buf, sizeof(buf)-1)) <= 0 ) {
   // really bad protocol error
-  clients_delete(client);
   return -1;
  }
@@ -256,10 +280,9 @@
 
 
-int emul_rplay_on_quit(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen) {
- clients_delete(client);
+static int emul_rplay_on_quit(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen) {
  return -1;
 }
 
-int emul_rplay_on_help(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen) {
+static int emul_rplay_on_help(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen) {
  struct emul_rplay_command * c;
 
@@ -276,5 +299,5 @@
 
 
-int emul_rplay_on_play(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen) {
+static int emul_rplay_on_play(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen) {
  struct roar_keyval        * kvr, * rate, * bits, * channels, * format, * byteorder;
  struct roar_audio_info      info;
@@ -370,5 +393,5 @@
 }
 
-int emul_rplay_on_put(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen) {
+static int emul_rplay_on_put(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen) {
  struct roar_keyval * kvr;
  int stream;
@@ -418,8 +441,8 @@
 }
 
-int emul_rplay_on_set(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen);
-int emul_rplay_on_modify(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen);
-
-int emul_rplay_on_pause(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen) {
+//static int emul_rplay_on_set(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen);
+//static int emul_rplay_on_modify(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen);
+
+static int emul_rplay_on_pause(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen) {
  struct roar_keyval * kvr;
  int stream;
@@ -450,5 +473,5 @@
 }
 
-int emul_rplay_on_continue(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen) {
+static int emul_rplay_on_continue(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen) {
  struct roar_keyval * kvr;
  int stream;
@@ -479,5 +502,13 @@
 }
 
-int emul_rplay_on_stop(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen);
+//static int emul_rplay_on_stop(int client, struct emul_rplay_command * cmd, struct roar_vio_calls * vio, struct roar_keyval * kv, size_t kvlen);
+
+struct roar_dl_proto __proto_common_rplay = {
+ .proto = ROAR_PROTO_RPLAY,
+ .description = "RPlay emulation",
+ .flags = ROAR_DL_PROTO_FLAGS_NONE,
+ .set_proto = emul_rplay_set_proto,
+ .handle = emul_rplay_check_client
+};
 
 #endif
