Index: ChangeLog
===================================================================
--- ChangeLog	(revision 5604)
+++ ChangeLog	(revision 5606)
@@ -17,4 +17,5 @@
 	* Added roar_buffer_moveintoqueue() (Closes: #283) (pr1)
 	* Typo corrections (Closes: #282) (pr1)
+	* Updated common protocol interface (Closes: #257, #256) (pr1)
 
 v. 1.0beta3 - Sun Jul 15 2012 26:08 CEST
Index: include/libroar/roardl.h
===================================================================
--- include/libroar/roardl.h	(revision 5582)
+++ include/libroar/roardl.h	(revision 5606)
@@ -332,7 +332,7 @@
    struct roar_dl_lhandle * lhandle  // The registering handle.
                                      // This is valid until the object is unregistered.
-                                     // Only roar_dl_context_restore() and roar_dl_context_store()
-                                     // may be used on this object. Result of all other functions
-                                     // is undefined.
+                                     // Only roar_dl_context_restore(), roar_dl_context_store()
+                                     // and roar_dl_getpara() may be used on this object.
+                                     // Result of all other functions is undefined.
  );
  void * userdata; // The user data pointer passed to the callback.
@@ -350,10 +350,10 @@
  const char * description;
  const int flags;
- int (*set_proto)(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen);
- int (*unset_proto)(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen);
- int (*handle)(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen);
- int (*flush)(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen);
- int (*flushed)(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen);
- int (*status)(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen);
+ int (*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);
+ int (*unset_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);
+ int (*handle)(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);
+ int (*flush)(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);
+ int (*flushed)(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);
+ int (*status)(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);
 };
 
Index: plugins/universal/protocol-daytime.c
===================================================================
--- plugins/universal/protocol-daytime.c	(revision 5605)
+++ plugins/universal/protocol-daytime.c	(revision 5606)
@@ -26,5 +26,5 @@
 #include <roaraudio.h>
 
-static int _set_proto(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) {
+static int _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) {
  struct roar_buffer * buf;
  void * data;
@@ -33,5 +33,5 @@
  char * date = asctime(gmtime(&now));
 
- (void)client, (void)vio, (void)userdata, (void)para, (void)paralen;
+ (void)client, (void)vio, (void)userdata, (void)protopara, (void)protoparalen, (void)pluginpara;
 
  len = roar_mm_strlen(date) + 1;
@@ -48,6 +48,6 @@
 }
 
-static int _flushed(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) {
- (void)client, (void)vio, (void)obuffer, (void)userdata, (void)para, (void)paralen;
+static int _flushed(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) {
+ (void)client, (void)vio, (void)obuffer, (void)userdata, (void)protopara, (void)protoparalen, (void)pluginpara;
 
  roar_err_set(ROAR_ERROR_NODATA);
Index: plugins/universal/protocol-discard.c
===================================================================
--- plugins/universal/protocol-discard.c	(revision 5605)
+++ plugins/universal/protocol-discard.c	(revision 5606)
@@ -26,8 +26,8 @@
 #include <roaraudio.h>
 
-static int _handle(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) {
+static int _handle(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[4096];
 
- (void)client, (void)obuffer, (void)userdata, (void)para, (void)paralen;
+ (void)client, (void)obuffer, (void)userdata, (void)protopara, (void)protoparalen, (void)pluginpara;
 
  if ( roar_vio_read(vio, buf, sizeof(buf)) < 1 ) {
Index: plugins/universal/protocol-echo.c
===================================================================
--- plugins/universal/protocol-echo.c	(revision 5605)
+++ plugins/universal/protocol-echo.c	(revision 5606)
@@ -26,10 +26,10 @@
 #include <roaraudio.h>
 
-static int _handle(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) {
+static int _handle(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_buffer * buf;
  void * data;
  ssize_t len;
 
- (void)client, (void)userdata, (void)para, (void)paralen;
+ (void)client, (void)userdata, (void)protopara, (void)protoparalen, (void)pluginpara;
 
  ROAR_DBG("_handle(client=%i, vio=%p) = ?", client, vio);
Index: plugins/universal/tic-tac-toe.c
===================================================================
--- plugins/universal/tic-tac-toe.c	(revision 5603)
+++ plugins/universal/tic-tac-toe.c	(revision 5606)
@@ -253,8 +253,8 @@
 }
 
-static int _set_proto(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) {
+static int _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) {
  game_state * state;
 
- (void)client, (void)vio, (void)obuffer, (void)para, (void)paralen;
+ (void)client, (void)vio, (void)obuffer, (void)protopara, (void)protoparalen, (void)pluginpara;
 
  state = roar_mm_malloc(sizeof(game_state));
@@ -301,5 +301,5 @@
 }
 
-static int _handle(int client, struct roar_vio_calls * vio, struct roar_buffer ** obuffer, void ** userdata, const struct roar_keyval * para, ssize_t paralen) {
+static int _handle(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[32];
  ssize_t len;
@@ -310,5 +310,5 @@
  char c;
 
- (void)client, (void)obuffer, (void)para, (void)paralen;
+ (void)client, (void)obuffer, (void)protopara, (void)protoparalen, (void)pluginpara;
 
  ROAR_DBG("check_client(client=%i, vio=%p) = ?", client, vio);
Index: roard/clients.c
===================================================================
--- roard/clients.c	(revision 5590)
+++ roard/clients.c	(revision 5606)
@@ -143,4 +143,5 @@
                          struct roard_listen * lsock, struct sockaddr * sockaddr, socklen_t addrlen) {
  const struct roard_proto_handle * protohandle;
+ struct roar_dl_librarypara * pluginpara;
  struct roar_vio_calls    vio;
  struct roar_client_server * cs;
@@ -287,7 +288,10 @@
         supported = 1;
         if ( protohandle->impl.common->set_proto != NULL ) {
-         if ( protohandle->impl.common->set_proto(client, &vio, &(cs->outbuf), &(cs->protoinst), protohandle->para, protohandle->paralen) == -1 ) {
+         pluginpara = roar_dl_getpara(protohandle->lhandle); // will return NULL in case protohandle->lhandle is NULL.
+         if ( protohandle->impl.common->set_proto(client, &vio, &(cs->outbuf), &(cs->protoinst), protohandle->para, protohandle->paralen, pluginpara) == -1 ) {
           supported = 0;
          }
+         if ( pluginpara != NULL )
+          roar_dl_para_unref(pluginpara);
         }
        break;
@@ -312,4 +316,5 @@
  struct roar_client_server * cs;
  const struct roard_proto_handle * proto;
+ struct roar_dl_librarypara * pluginpara;
  struct roar_vio_calls vio;
  int i;
@@ -337,5 +342,8 @@
      if ( proto->impl.common->unset_proto != NULL ) {
       roar_vio_open_fh_socket(&vio, clients_get_fh(id));
-      proto->impl.common->unset_proto(id, &vio, &(cs->outbuf), &(cs->protoinst), proto->para, proto->paralen);
+      pluginpara = roar_dl_getpara(proto->lhandle); // will return NULL in case protohandle->lhandle is NULL.
+      proto->impl.common->unset_proto(id, &vio, &(cs->outbuf), &(cs->protoinst), proto->para, proto->paralen, pluginpara);
+      if ( pluginpara != NULL )
+       roar_dl_para_unref(pluginpara);
      }
     break;
@@ -723,4 +731,5 @@
  struct roar_error_state errstate;
  const struct roard_proto_handle * proto;
+ struct roar_dl_librarypara * pluginpara;
  int command_error;
  char * data = NULL;
@@ -834,6 +843,10 @@
        break;
       case ROARD_PROTO_TYPE_COMMON:
-        if ( proto->impl.common->handle != NULL )
-         rv = proto->impl.common->handle(id, &vio, &(cs->outbuf), &(cs->protoinst), proto->para, proto->paralen);
+        if ( proto->impl.common->handle != NULL ) {
+         pluginpara = roar_dl_getpara(proto->lhandle); // will return NULL in case protohandle->lhandle is NULL.
+         rv = proto->impl.common->handle(id, &vio, &(cs->outbuf), &(cs->protoinst), proto->para, proto->paralen, pluginpara);
+         if ( pluginpara != NULL )
+          roar_dl_para_unref(pluginpara);
+        }
         if ( rv == -1 )
          rv = clients_delete(id);
@@ -858,4 +871,5 @@
  struct roar_client              * c;
  const struct roard_proto_handle * p;
+ struct roar_dl_librarypara * pluginpara;
  size_t len;
  ssize_t ret;
@@ -892,7 +906,10 @@
      if ( p->lhandle != NULL )
       roar_dl_context_restore(p->lhandle);
-     rv = p->impl.common->flush(id, &vio, &(cs->outbuf), &(cs->protoinst), p->para, p->paralen);
+     pluginpara = roar_dl_getpara(p->lhandle); // will return NULL in case protohandle->lhandle is NULL.
+     rv = p->impl.common->flush(id, &vio, &(cs->outbuf), &(cs->protoinst), p->para, p->paralen, pluginpara);
      if ( p->lhandle != NULL )
       roar_dl_context_store(p->lhandle);
+     if ( pluginpara != NULL )
+      roar_dl_para_unref(pluginpara);
      if ( rv == -1 )
       rv = clients_delete(id);
@@ -946,7 +963,10 @@
       if ( p->lhandle != NULL )
        roar_dl_context_restore(p->lhandle);
-      rv = p->impl.common->flushed(id, &vio, &(cs->outbuf), &(cs->protoinst), p->para, p->paralen);
+      pluginpara = roar_dl_getpara(p->lhandle); // will return NULL in case protohandle->lhandle is NULL.
+      rv = p->impl.common->flushed(id, &vio, &(cs->outbuf), &(cs->protoinst), p->para, p->paralen, pluginpara);
       if ( p->lhandle != NULL )
        roar_dl_context_store(p->lhandle);
+      if ( pluginpara != NULL )
+       roar_dl_para_unref(pluginpara);
       if ( rv == -1 )
        rv = clients_delete(id);
