Index: libroar/vio_dstr.c
===================================================================
--- libroar/vio_dstr.c	(revision 5282)
+++ libroar/vio_dstr.c	(revision 5367)
@@ -41,5 +41,5 @@
  const char * name;
  int (* setdef) (struct roar_vio_dstr_chain * cur,   struct roar_vio_dstr_chain * next);
- int (* openvio)(struct roar_vio_calls      * calls, struct roar_vio_calls      * dst, struct roar_vio_dstr_chain * cur);
+ int (* openvio)(struct roar_vio_calls      * calls, struct roar_vio_calls      * dst, struct roar_vio_dstr_chain * cur, struct roar_vio_dstr_chain * next);
  int    pdeftype[16];
 } _roar_vio_dstr_objs[] = {
@@ -105,20 +105,20 @@
 
  {ROAR_VIO_DSTR_OBJT_SOCKS,      "socks",
-      NULL, NULL,
+      roar_vio_proxy_setdef, roar_vio_proxy_openvio,
       {ROAR_VIO_DEF_TYPE_EOL}},
  {ROAR_VIO_DSTR_OBJT_SOCKS4,     "socks4",
-      NULL, NULL,
+      roar_vio_proxy_setdef, roar_vio_proxy_openvio,
       {ROAR_VIO_DEF_TYPE_EOL}},
  {ROAR_VIO_DSTR_OBJT_SOCKS4A,    "socks4a",
-      NULL, NULL,
+      roar_vio_proxy_setdef, roar_vio_proxy_openvio,
       {ROAR_VIO_DEF_TYPE_EOL}},
  {ROAR_VIO_DSTR_OBJT_SOCKS4D,    "socks4d",
-      NULL, NULL,
+      roar_vio_proxy_setdef, roar_vio_proxy_openvio,
       {ROAR_VIO_DEF_TYPE_EOL}},
  {ROAR_VIO_DSTR_OBJT_SOCKS5,     "socks5",
-      NULL, NULL,
+      roar_vio_proxy_setdef, roar_vio_proxy_openvio,
       {ROAR_VIO_DEF_TYPE_EOL}},
  {ROAR_VIO_DSTR_OBJT_SSH,        "ssh",
-      NULL, NULL,
+      roar_vio_proxy_setdef, roar_vio_proxy_openvio,
       {ROAR_VIO_DEF_TYPE_EOL}},
 
@@ -265,5 +265,6 @@
                                     int (*openvio)(struct roar_vio_calls      * calls,
                                                    struct roar_vio_calls      * dst,
-                                                   struct roar_vio_dstr_chain * cur)) {
+                                                   struct roar_vio_dstr_chain * cur,
+                                                   struct roar_vio_dstr_chain * next)) {
  struct _roar_vio_dstr_type * ret;
 
@@ -362,7 +363,9 @@
  switch (def->type) {
   case ROAR_VIO_DEF_TYPE_NONE:
+    ROAR_DBG("roar_vio_open_default(calls=%p, def=%p, opts='%s'): def->type=%i, dummy open", calls, def, opts, (int)def->type);
    break;
 #ifdef ROAR_HAVE_IO_POSIX
   case ROAR_VIO_DEF_TYPE_FILE:
+    ROAR_DBG("roar_vio_open_default(calls=%p, def=%p, opts='%s'): def->type=%i, file open", calls, def, opts, (int)def->type);
     if ( _open_file(calls, def->d.file, def->o_flags, def->o_mode) == -1 ) {
      ROAR_DBG("roar_vio_open_default(*): Can not open file: %i", roar_error);
@@ -372,16 +375,20 @@
 #endif
   case ROAR_VIO_DEF_TYPE_SOCKET:
+    ROAR_DBG("roar_vio_open_default(calls=%p, def=%p, opts='%s'): def->type=%i, socket open", calls, def, opts, (int)def->type);
      if ( roar_vio_open_def_socket(calls, def, opts) == -1 )
       return -1;
    break;
   case ROAR_VIO_DEF_TYPE_FH:
+    ROAR_DBG("roar_vio_open_default(calls=%p, def=%p, opts='%s'): def->type=%i, fh open", calls, def, opts, (int)def->type);
     if ( roar_vio_open_fh(calls, def->d.fh) == -1 )
      return -1;
    break;
   case ROAR_VIO_DEF_TYPE_SOCKETFH:
+    ROAR_DBG("roar_vio_open_default(calls=%p, def=%p, opts='%s'): def->type=%i, socket fh open", calls, def, opts, (int)def->type);
     if ( roar_vio_open_fh_socket(calls, def->d.fh) == -1 )
      return -1;
    break;
   default:
+    ROAR_DBG("roar_vio_open_default(calls=%p, def=%p, opts='%s') = -1 // error=NOTSUP", calls, def, opts, (int)def->type);
     roar_err_set(ROAR_ERROR_NOTSUP);
     return -1;
@@ -849,7 +856,7 @@
  }
 
- for (i = 0; (c = &chain[i])->type != ROAR_VIO_DSTR_OBJT_EOL; i++) {
-  ROAR_DBG("roar_vio_dstr_build_chain(*): i=%i, c->type=0x%.4x(%s): need_vio=%i, def->o_flags=%i", i,
-                   c->type & 0xFFFF, roar_vio_dstr_get_name(c->type), c->need_vio, c->def->o_flags);
+ for (i = 0; (c = &(chain[i]))->type != ROAR_VIO_DSTR_OBJT_EOL; i++) {
+  ROAR_DBG("roar_vio_dstr_build_chain(*): i=%i, c->type=0x%.4x(%s): need_vio=%i, def(%p)->o_flags=%i", i,
+                   c->type & 0xFFFF, roar_vio_dstr_get_name(c->type), c->need_vio, c->def, c->def != NULL ? c->def->o_flags : -1);
 
   if ( c->need_vio ) {
@@ -881,5 +888,4 @@
 #ifdef ROAR_HAVE_LIBZ
     case ROAR_VIO_DSTR_OBJT_GZIP:
-      //if ( roar_vio_open_gzip(tc, prev, -1) == -1 ) {
       if ( roar_vio_open_zlib(tc, prev, -1, 1) == -1 ) {
        _ret(-1);
@@ -887,5 +893,4 @@
      break;
     case ROAR_VIO_DSTR_OBJT_ZLIB:
-      //if ( roar_vio_open_gzip(tc, prev, -1) == -1 ) {
       if ( roar_vio_open_zlib(tc, prev, -1, 0) == -1 ) {
        _ret(-1);
@@ -960,5 +965,5 @@
       }
 
-      if ( type->openvio(tc, prev, c) == -1 ) {
+      if ( type->openvio(tc, prev, c, &(chain[i+1])) == -1 ) {
        _ret(-1);
       }
