]> arthur.barton.de Git - netatalk.git/commitdiff
rework getstatus. use several ASP packets if the client allows it, otherwise just...
authorbfernhomberg <bfernhomberg>
Thu, 1 Jul 2004 01:53:21 +0000 (01:53 +0000)
committerbfernhomberg <bfernhomberg>
Thu, 1 Jul 2004 01:53:21 +0000 (01:53 +0000)
etc/afpd/status.c
libatalk/asp/asp_getsess.c

index 763a84137d75e7f6c3dda73dbbcead5d6db2ad31..1927cf6fbbbac316e0fb73ca06a1f1f8901b82eb 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: status.c,v 1.13.6.8 2004-06-24 01:22:36 bfernhomberg Exp $
+ * $Id: status.c,v 1.13.6.9 2004-07-01 01:53:21 bfernhomberg Exp $
  *
  * Copyright (c) 1990,1993 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -419,7 +419,7 @@ static int status_utf8servername(char *data, int *nameoffset,
 
        /* set offset to 0 */
        memset(begin + *nameoffset, 0, sizeof(offset));
-        data = begin;
+        data = begin + offset;
     }
     else {
        namelen = htons(len);
@@ -475,11 +475,9 @@ void status_reset()
 
 
 /* ---------------------
- * returns 1 if both packets (ASP and DSI) could be set
- * forceasp 1 enforces build of ASP packet
  */
-static int do_status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig,
-                 const struct afp_options *options, int forceasp)
+void status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig,
+                 const struct afp_options *options)
 {
     ASP asp;
     DSI *dsi;
@@ -488,28 +486,18 @@ static int do_status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig,
     int ret = 0;
 
     if (!(aspconfig || dsiconfig) || !options)
-        return ret;
-
-    if (forceasp) {
-        if (!aspconfig)
-            return ret;
-        status = aspconfig->status;
-       maxstatuslen=ATP_MAXDATA-4;
-    } 
-    else /* dsi */
-    {
-       if (!dsiconfig)
-            return ret;
-         status = dsiconfig->status;
-        maxstatuslen=sizeof(dsiconfig->status);
-    }
+        return;
 
     if (aspconfig) {
+        status = aspconfig->status;
+        maxstatuslen=sizeof(aspconfig->status);
         asp = aspconfig->obj.handle;
     } else
         asp = NULL;
-
+       
     if (dsiconfig) {
+        status = dsiconfig->status;
+        maxstatuslen=sizeof(dsiconfig->status);
         dsi = dsiconfig->obj.handle;
     } else
         dsi = NULL;
@@ -562,21 +550,16 @@ static int do_status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig,
         statuslen = status_utf8servername(status, &c, dsi, options);
 
 #ifndef NO_DDP
-    if (forceasp) {
+    if (aspconfig) {
+        if (dsiconfig) /* status is dsiconfig->status */
+            memcpy(aspconfig->status, status, statuslen);
         asp_setstatus(asp, status, statuslen);
         aspconfig->signature = status + sigoff;
         aspconfig->statuslen = statuslen;
     }
 #endif /* ! NO_DDP */
 
-    if (!forceasp) {
-        if (aspconfig && statuslen <= ATP_MAXDATA-4) { /* set ASP as well, lenght matches */
-            memcpy(aspconfig->status, status, ATP_MAXDATA);
-            asp_setstatus(asp, aspconfig->status, statuslen);
-            aspconfig->signature = aspconfig->status + sigoff;
-            aspconfig->statuslen = statuslen;
-            ret=1;
-        }
+    if (dsiconfig) {
         if ((options->flags & OPTION_CUSTOMICON) == 0) {
             status_icon(status, apple_tcp_icon, sizeof(apple_tcp_icon), 0);
         }
@@ -584,22 +567,6 @@ static int do_status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig,
         dsiconfig->signature = status + sigoff;
         dsiconfig->statuslen = statuslen;
     }
-
-    return ret;
-}
-
-void status_init(AFPConfig *aspconfig, AFPConfig *dsiconfig,
-                 const struct afp_options *options)
-{
-     int ret = 0;
-
-     if (dsiconfig) {
-         ret = do_status_init(aspconfig, dsiconfig, options, 0);
-         if (!ret)
-             LOG(log_warning, logtype_afpd, "status packet to long for ASP, buildling extra packet");
-     }
-     if (!ret && aspconfig)
-         do_status_init(aspconfig, dsiconfig, options, 1);
 }
 
 /* this is the same as asp/dsi_getstatus */
index 331d32570be62f5c8bb85e6589e9d1bf037fa6b3..54431d438ab524f622ed857bad72549983a0c56a 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: asp_getsess.c,v 1.7.8.3 2004-04-27 22:47:32 didg Exp $
+ * $Id: asp_getsess.c,v 1.7.8.4 2004-07-01 01:53:21 bfernhomberg Exp $
  *
  * Copyright (c) 1990,1996 Regents of The University of Michigan.
  * All Rights Reserved.  See COPYRIGHT.
@@ -119,15 +119,17 @@ static void set_asp_ac(int sid, struct asp_child *tmp);
 ASP asp_getsession(ASP asp, server_child *server_children, 
                   const int tickleval)
 {
-    struct sigaction action;
-    struct itimerval timer;
-    struct sockaddr_at sat;
-    struct atp_block   atpb;
+    struct sigaction    action;
+    struct itimerval    timer;
+    struct sockaddr_at  sat;
+    struct atp_block    atpb;
     ATP                 atp;
-    struct iovec       iov[ 8 ];
+    struct iovec        iov[ 8 ];
     pid_t               pid;
-    int                        i, sid;
-    u_int16_t          asperr;
+    int                 i, iovcnt, sid;
+    u_int16_t           asperr;
+    char                *buf;
+    int                 buflen;
 
     if (!asp->inited) {
       if (!(children = server_children))
@@ -197,13 +199,45 @@ ASP asp_getsession(ASP asp, server_child *server_children,
       printf( "asp stat\n" );
 #endif /* EBUG */
       if ( asp->asp_slen > 0 ) {
-       asp->cmdbuf[0] = 0;
-       memcpy( asp->cmdbuf + 4, asp->asp_status, asp->asp_slen );
-       iov[ 0 ].iov_base = asp->cmdbuf;
-       iov[ 0 ].iov_len = 4 + asp->asp_slen;
-       atpb.atp_sresiov = iov;
-       atpb.atp_sresiovcnt = 1;
-       atp_sresp( asp->asp_atp, &atpb );
+        i = 0;
+        while(atpb.atp_bitmap) {
+            i++;
+            atpb.atp_bitmap >>= 1;
+        }
+
+       /* asp->data is big enough ... */
+        memcpy( asp->data, asp->asp_status, MIN(asp->asp_slen, i*ASP_CMDSIZ));
+       
+        buflen = MIN(asp->asp_slen, i*ASP_CMDSIZ);
+        buf = asp->data;
+        iovcnt = 0;
+
+        /* If status information is too big to fit into the available
+         * ASP packets, we simply send as much as we can.
+         * Older client versions will most likely not be able to use
+         * the additional information anyway, like directory services
+         * or UTF8 server name. A very long fqdn could be a problem,
+         * we could end up with an invalid address list.
+         */
+        do {
+            iov[ iovcnt ].iov_base = buf;
+            memmove(buf + ASP_HDRSIZ, buf, buflen);
+            memset( iov[ iovcnt ].iov_base, 0, ASP_HDRSIZ );
+
+           if ( buflen > ASP_CMDSIZ ) {
+                buf += ASP_CMDMAXSIZ;
+                buflen -= ASP_CMDSIZ;
+                iov[ iovcnt ].iov_len = ASP_CMDMAXSIZ;
+            } else {
+                iov[ iovcnt ].iov_len = buflen + ASP_HDRSIZ;
+                buflen = 0;
+            }
+            iovcnt++;
+        } while ( iovcnt < i && buflen > 0 );
+
+        atpb.atp_sresiovcnt = iovcnt;
+        atpb.atp_sresiov = iov;
+        atp_sresp( asp->asp_atp, &atpb );
       }
       break;