]> arthur.barton.de Git - netatalk.git/blob - libatalk/dsi/dsi_opensess.c
afpd.conf.tmpl: Merge remote-tracking branch 'remotes/origin/branch-netatalk-2-1'
[netatalk.git] / libatalk / dsi / dsi_opensess.c
1 /*
2  * $Id: dsi_opensess.c,v 1.4 2005-09-07 15:27:29 didg Exp $
3  *
4  * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
5  * All rights reserved. See COPYRIGHT.
6  */
7
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif /* HAVE_CONFIG_H */
11
12 #include <stdio.h>
13 #include <string.h>
14 #include <sys/types.h>
15
16 #include <atalk/dsi.h>
17
18 /* OpenSession. set up the connection */
19 void dsi_opensession(DSI *dsi)
20 {
21   u_int32_t i = 0; /* this serves double duty. it must be 4-bytes long */
22   int offs;
23
24   /* parse options */
25   while (i < dsi->cmdlen) {
26     switch (dsi->commands[i++]) {
27     case DSIOPT_ATTNQUANT:
28       memcpy(&dsi->attn_quantum, dsi->commands + i + 1, dsi->commands[i]);
29       dsi->attn_quantum = ntohl(dsi->attn_quantum);
30
31     case DSIOPT_SERVQUANT: /* just ignore these */
32     default:
33       i += dsi->commands[i] + 1; /* forward past length tag + length */
34       break;
35     }
36   }
37
38   /* let the client know the server quantum. we don't use the
39    * max server quantum due to a bug in appleshare client 3.8.6. */
40   dsi->header.dsi_flags = DSIFL_REPLY;
41   dsi->header.dsi_code = 0;
42   /* dsi->header.dsi_command = DSIFUNC_OPEN;*/
43
44   dsi->cmdlen = 2 * (2 + sizeof(i)); /* length of data. dsi_send uses it. */
45
46   /* DSI Option Server Request Quantum */
47   dsi->commands[0] = DSIOPT_SERVQUANT;
48   dsi->commands[1] = sizeof(i);
49   i = htonl(( dsi->server_quantum < DSI_SERVQUANT_MIN || 
50               dsi->server_quantum > DSI_SERVQUANT_MAX ) ? 
51             DSI_SERVQUANT_DEF : dsi->server_quantum);
52   memcpy(dsi->commands + 2, &i, sizeof(i));
53
54   /* AFP replaycache size option */
55   offs = 2 + sizeof(i);
56   dsi->commands[offs] = DSIOPT_REPLCSIZE;
57   dsi->commands[offs+1] = sizeof(i);
58   i = htonl(REPLAYCACHE_SIZE);
59   memcpy(dsi->commands + offs + 2, &i, sizeof(i));
60   dsi_send(dsi);
61 }