netatalk 4.5.0
Free and Open Source Apple Filing Protocol (AFP) Server
Loading...
Searching...
No Matches
include/atalk/dsi.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 1997 Adrian Sun (asun@zoology.washington.edu)
3 * All rights reserved.
4 */
5
6#ifndef _ATALK_DSI_H
7#define _ATALK_DSI_H
8
9#include <sys/types.h>
10#include <arpa/inet.h>
11#include <netinet/in.h>
12#include <signal.h>
13#include <sys/socket.h>
14#include <sys/time.h>
15
16#include <atalk/afp.h>
17#include <atalk/globals.h>
18#include <atalk/server_child.h>
19
40
41#define DSI_BLOCKSIZ 16
42 struct dsi_block {
43 uint8_t dsi_flags;
44 uint8_t dsi_command;
45 uint16_t dsi_requestID;
46 union {
47 uint32_t dsi_code;
48 uint32_t dsi_doff;
49 } dsi_data;
50 uint32_t dsi_len;
51 uint32_t dsi_reserved;
52};
53
54#define DSI_DATASIZ 65536
55
56/* child and parent processes might interpret a couple of these
57 * differently. */
58 typedef struct DSI {
59 struct DSI *next;
60 AFPObj *AFPobj;
61 int statuslen;
62 char status[1400];
63 char *signature;
64 struct dsi_block header;
65 struct sockaddr_storage server, client;
66 struct itimerval timer;
67 int tickle;
68 int in_write;
70 int msg_request;
71 int down_request;
72
73 uint32_t attn_quantum, datasize, server_quantum;
74 uint16_t serverID, clientID;
75 uint8_t *commands;
76 uint8_t data[DSI_DATASIZ];
77 size_t datalen, cmdlen;
78 off_t read_count, write_count;
79 uint32_t flags;
80 int socket;
81 int serversock;
82
83 /* DSI readahead buffer used for buffered reads in dsi_peek */
84 size_t dsireadbuf;
85 char *buffer;
86 char *start;
87 char *eof;
88 char *end;
89
90#ifdef USE_ZEROCONF
91 char *zeroconfname;
92 int zeroconf_registered;
93#endif
94
95 /* protocol specific open/close */
96 pid_t (*proto_open)(struct DSI *);
97 void (*proto_close)(struct DSI *);
98} DSI;
99
100/* DSI flags */
101#define DSIFL_REQUEST 0x00
102#define DSIFL_REPLY 0x01
103#define DSIFL_MAX 0x01
104
105/* DSI session options */
106#define DSIOPT_SERVQUANT 0x00
107#define DSIOPT_ATTNQUANT 0x01
108#define DSIOPT_REPLCSIZE 0x02
109
110/* DSI Commands */
111#define DSIFUNC_CLOSE 1
112#define DSIFUNC_CMD 2
113#define DSIFUNC_STAT 3
114#define DSIFUNC_OPEN 4
115#define DSIFUNC_TICKLE 5
116#define DSIFUNC_WRITE 6
117#define DSIFUNC_ATTN 8
118#define DSIFUNC_MAX 8
119
120/* DSI Error codes: most of these aren't used. */
121#define DSIERR_OK 0x0000
122#define DSIERR_BADVERS 0xfbd6
123#define DSIERR_BUFSMALL 0xfbd5
124#define DSIERR_NOSESS 0xfbd4
125#define DSIERR_NOSERV 0xfbd3
126#define DSIERR_PARM 0xfbd2
127#define DSIERR_SERVBUSY 0xfbd1
128#define DSIERR_SESSCLOS 0xfbd0
129#define DSIERR_SIZERR 0xfbcf
130#define DSIERR_TOOMANY 0xfbce
131#define DSIERR_NOACK 0xfbcd
132
133/* server and client quanta */
134#define DSI_DEFQUANT 2
135#define DSI_SERVQUANT_MAX 0xffffffff
136#define DSI_SERVQUANT_MIN 32000
137#define DSI_SERVQUANT_DEF 0x100000L
138
140#define DSI_AFPOVERTCP_PORT 548
141
142/* DSI session State flags */
143#define DSI_DATA (1 << 0)
144#define DSI_RUNNING (1 << 1)
145#define DSI_SLEEPING (1 << 2)
146#define DSI_EXTSLEEP (1 << 3)
147#define DSI_DISCONNECTED (1 << 4)
148#define DSI_DIE (1 << 5)
149#define DSI_NOREPLY (1 << 6)
150#define DSI_RECONSOCKET (1 << 7)
151#define DSI_RECONINPROG (1 << 8)
152#define DSI_AFP_LOGGED_OUT (1 << 9)
153
154/* basic initialization: dsi_init.c */
155 extern DSI *dsi_init(AFPObj *obj, const char *hostname, const char *address,
156 const char *port);
157 extern void dsi_setstatus(DSI *, char *, const size_t);
158 extern int dsi_tcp_init(DSI *dsi, const char *hostname, const char *address,
159 const char *port);
160 extern void dsi_free(DSI *dsi);
161
162/* in dsi_getsess.c */
163 extern int dsi_getsession(DSI *, server_child_t *, const int, afp_child_t **);
164 extern void dsi_kill(int);
165
166
167/* DSI Commands: individual files */
168 extern void dsi_opensession(DSI *);
169 extern int dsi_attention(DSI *, AFPUserBytes);
170 extern int dsi_cmdreply(DSI *, const int);
171 extern int dsi_tickle(DSI *);
172 extern void dsi_getstatus(DSI *);
173 extern void dsi_close(DSI *);
174
175#define DSI_NOWAIT 1
176#define DSI_MSG_MORE 2
177
178/* low-level stream commands -- in dsi_stream.c */
179 extern ssize_t dsi_stream_write(DSI *, void *, const size_t, const int mode);
180 extern size_t dsi_stream_read(DSI *, void *, const size_t);
181 extern int dsi_stream_send(DSI *, void *, size_t);
182 extern int dsi_stream_receive(DSI *);
183 extern int dsi_disconnect(DSI *dsi);
184
185#ifdef WITH_SENDFILE
186 extern ssize_t dsi_stream_read_file(DSI *, int, off_t off, const size_t len,
187 const int err);
188#endif
189
190/* client writes -- dsi_write.c */
191 extern size_t dsi_writeinit(DSI *, void *, const size_t);
192 extern size_t dsi_write(DSI *, void *, const size_t);
193 extern void dsi_writeflush(DSI *);
194#define dsi_wrtreply(a,b) dsi_cmdreply(a,b)
195
196/* client reads -- dsi_read.c */
197 extern ssize_t dsi_readinit(DSI *, void *, const size_t, const size_t,
198 const int);
199 extern ssize_t dsi_read(DSI *, void *, const size_t);
200 extern void dsi_readdone(DSI *);
201
202/* some useful macros */
203#define dsi_serverID(x) ((x)->serverID++)
204#define dsi_send(x) do { \
205 (x)->header.dsi_len = htonl((x)->cmdlen); \
206 dsi_stream_send((x), (x)->commands, (x)->cmdlen); \
207 } while (0)
208
209#endif /* atalk/dsi.h */
afp.h
AFPUserBytes
uint16_t AFPUserBytes
Definition afp.h:30
dsi
static DSI * dsi
Definition afparg.c:39
globals.h
dsi_write
size_t dsi_write(DSI *, void *, const size_t)
Definition dsi_write.c:57
dsi_attention
int dsi_attention(DSI *, AFPUserBytes)
send an attention.
Definition dsi_attn.c:25
dsi_stream_read
size_t dsi_stream_read(DSI *, void *, const size_t)
Read data from DSI buffer.
Definition dsi_stream.c:534
dsi_stream_write
ssize_t dsi_stream_write(DSI *, void *, const size_t, const int mode)
write raw DSI data
Definition dsi_stream.c:304
dsi_writeinit
size_t dsi_writeinit(DSI *, void *, const size_t)
Definition dsi_write.c:26
dsi_setstatus
void dsi_setstatus(DSI *, char *, const size_t)
dsi_stream_send
int dsi_stream_send(DSI *, void *, size_t)
write data.
Definition dsi_stream.c:581
dsi_init
DSI * dsi_init(AFPObj *obj, const char *hostname, const char *address, const char *port)
Definition dsi_init.c:17
dsi_getsession
int dsi_getsession(DSI *, server_child_t *, const int, afp_child_t **)
Start a DSI session, fork an afpd process.
Definition dsi_getsess.c:36
dsi_stream_read_file
ssize_t dsi_stream_read_file(DSI *, int, off_t off, const size_t len, const int err)
Definition dsi_stream.c:371
dsi_readinit
ssize_t dsi_readinit(DSI *, void *, const size_t, const size_t, const int)
streaming i/o for afp_read.
Definition dsi_read.c:29
dsi_tcp_init
int dsi_tcp_init(DSI *dsi, const char *hostname, const char *address, const char *port)
Initialize DSI over TCP.
Definition dsi_tcp.c:435
dsi_opensession
void dsi_opensession(DSI *)
Definition dsi_opensess.c:20
dsi_writeflush
void dsi_writeflush(DSI *)
Definition dsi_write.c:75
dsi_tickle
int dsi_tickle(DSI *)
Definition dsi_tickle.c:20
dsi_disconnect
int dsi_disconnect(DSI *dsi)
Communication error with the client, enter disconnected state.
Definition dsi_stream.c:282
dsi_stream_receive
int dsi_stream_receive(DSI *)
Read DSI command and data.
Definition dsi_stream.c:662
dsi_free
void dsi_free(DSI *dsi)
Definition dsi_tcp.c:105
dsi_kill
void dsi_kill(int)
dsi_close
void dsi_close(DSI *)
Definition dsi_close.c:17
dsi_getstatus
void dsi_getstatus(DSI *)
Definition dsi_getstat.c:19
dsi_cmdreply
int dsi_cmdreply(DSI *, const int)
Definition dsi_cmdreply.c:19
dsi_read
ssize_t dsi_read(DSI *, void *, const size_t)
Definition dsi_read.c:57
dsi_readdone
void dsi_readdone(DSI *)
Definition dsi_read.c:51
hostname
static char hostname[MAXHOSTNAMELEN]
Definition lp.c:170
obj
static AFPObj obj
Definition netatalk.c:69
port
static unsigned char port
Definition pap.c:504
server_child.h
data structures and utility functions for child processes
afp_child_t
struct afp_child afp_child_t
AFPObj
Definition globals.h:166
DSI
Definition include/atalk/dsi.h:58
DSI::eof
char * eof
Definition include/atalk/dsi.h:87
DSI::serverID
uint16_t serverID
Definition include/atalk/dsi.h:74
DSI::AFPobj
AFPObj * AFPobj
Definition include/atalk/dsi.h:60
DSI::signature
char * signature
Definition include/atalk/dsi.h:63
DSI::tickle
int tickle
Definition include/atalk/dsi.h:67
DSI::msg_request
int msg_request
Definition include/atalk/dsi.h:70
DSI::datalen
size_t datalen
Definition include/atalk/dsi.h:77
DSI::client
struct sockaddr_storage server client
Definition include/atalk/dsi.h:65
DSI::start
char * start
Definition include/atalk/dsi.h:86
DSI::buffer
char * buffer
Definition include/atalk/dsi.h:85
DSI::cmdlen
size_t cmdlen
Definition include/atalk/dsi.h:77
DSI::read_count
off_t read_count
Definition include/atalk/dsi.h:78
DSI::in_write
int in_write
Definition include/atalk/dsi.h:68
DSI::proto_open
pid_t(* proto_open)(struct DSI *)
Definition include/atalk/dsi.h:96
DSI::datasize
uint32_t datasize
Definition include/atalk/dsi.h:73
DSI::write_count
off_t write_count
Definition include/atalk/dsi.h:78
DSI::down_request
int down_request
Definition include/atalk/dsi.h:71
DSI::end
char * end
Definition include/atalk/dsi.h:88
DSI::serversock
int serversock
Definition include/atalk/dsi.h:81
DSI::server_quantum
uint32_t server_quantum
Definition include/atalk/dsi.h:73
DSI::clientID
uint16_t clientID
Definition include/atalk/dsi.h:74
DSI::flags
uint32_t flags
Definition include/atalk/dsi.h:79
DSI::proto_close
void(* proto_close)(struct DSI *)
Definition include/atalk/dsi.h:97
DSI::data
uint8_t data[DSI_DATASIZ]
Definition include/atalk/dsi.h:76
DSI::socket
int socket
Definition include/atalk/dsi.h:80
DSI::dsireadbuf
size_t dsireadbuf
Definition include/atalk/dsi.h:84
DSI::status
char status[1400]
Definition include/atalk/dsi.h:62
DSI::attn_quantum
uint32_t attn_quantum
Definition include/atalk/dsi.h:73
DSI::timer
struct itimerval timer
Definition include/atalk/dsi.h:66
DSI::statuslen
int statuslen
Definition include/atalk/dsi.h:61
DSI::header
struct dsi_block header
Definition include/atalk/dsi.h:64
DSI::commands
uint8_t * commands
Definition include/atalk/dsi.h:75
DSI::next
struct DSI * next
Definition include/atalk/dsi.h:59
dsi_block
Definition include/atalk/dsi.h:42
dsi_block::dsi_command
uint8_t dsi_command
Definition include/atalk/dsi.h:44
dsi_block::dsi_code
uint32_t dsi_code
Definition include/atalk/dsi.h:47
dsi_block::dsi_len
uint32_t dsi_len
Definition include/atalk/dsi.h:50
dsi_block::dsi_requestID
uint16_t dsi_requestID
Definition include/atalk/dsi.h:45
dsi_block::dsi_doff
uint32_t dsi_doff
Definition include/atalk/dsi.h:48
dsi_block::dsi_reserved
uint32_t dsi_reserved
Definition include/atalk/dsi.h:51
dsi_block::dsi_flags
uint8_t dsi_flags
Definition include/atalk/dsi.h:43
dsi_block::dsi_data
union dsi_block::@150362255105244334275205120272303145121330114015 dsi_data
server_child_t
Definition server_child.h:47
server
Definition cnid_metad.c:111
DSI_DATASIZ
#define DSI_DATASIZ
Definition test/testsuite/dsi.h:58