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