1 | /****************************************************************************** |
---|
2 | * $Id: ipcparse.h 2227 2007-06-29 02:21:29Z joshe $ |
---|
3 | * |
---|
4 | * Copyright (c) 2007 Joshua Elsasser |
---|
5 | * |
---|
6 | * Permission is hereby granted, free of charge, to any person obtaining a |
---|
7 | * copy of this software and associated documentation files (the "Software"), |
---|
8 | * to deal in the Software without restriction, including without limitation |
---|
9 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
---|
10 | * and/or sell copies of the Software, and to permit persons to whom the |
---|
11 | * Software is furnished to do so, subject to the following conditions: |
---|
12 | * |
---|
13 | * The above copyright notice and this permission notice shall be included in |
---|
14 | * all copies or substantial portions of the Software. |
---|
15 | * |
---|
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
---|
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
---|
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
---|
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
---|
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
---|
21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
---|
22 | * DEALINGS IN THE SOFTWARE. |
---|
23 | *****************************************************************************/ |
---|
24 | |
---|
25 | #ifndef TR_DAEMON_IPC_H |
---|
26 | #define TR_DAEMON_IPC_H |
---|
27 | |
---|
28 | #include <inttypes.h> |
---|
29 | |
---|
30 | /* yay for typedefs, we can't forward declare benc_val_t or tr_info_t |
---|
31 | like with structs */ |
---|
32 | #include "bencode.h" |
---|
33 | #include "transmission.h" |
---|
34 | |
---|
35 | #define IPC_MIN_MSG_LEN ( 8 ) |
---|
36 | #define IPC_MAX_MSG_LEN ( 0x7fffffff - IPC_MIN_MSG_LEN ) |
---|
37 | |
---|
38 | enum ipc_msg |
---|
39 | { |
---|
40 | IPC_MSG_ADDMANYFILES = 0, |
---|
41 | IPC_MSG_ADDONEFILE, |
---|
42 | IPC_MSG_AUTOMAP, |
---|
43 | IPC_MSG_AUTOSTART, |
---|
44 | IPC_MSG_BAD, |
---|
45 | IPC_MSG_DIR, |
---|
46 | IPC_MSG_DOWNLIMIT, |
---|
47 | IPC_MSG_FAIL, |
---|
48 | IPC_MSG_GETAUTOMAP, |
---|
49 | IPC_MSG_GETAUTOSTART, |
---|
50 | IPC_MSG_GETDIR, |
---|
51 | IPC_MSG_GETDOWNLIMIT, |
---|
52 | IPC_MSG_GETINFO, |
---|
53 | IPC_MSG_GETINFOALL, |
---|
54 | IPC_MSG_GETPEX, |
---|
55 | IPC_MSG_GETPORT, |
---|
56 | IPC_MSG_GETSTAT, |
---|
57 | IPC_MSG_GETSTATALL, |
---|
58 | IPC_MSG_GETSUP, |
---|
59 | IPC_MSG_GETUPLIMIT, |
---|
60 | IPC_MSG_LOOKUP, |
---|
61 | IPC_MSG_INFO, |
---|
62 | IPC_MSG_NOOP, |
---|
63 | IPC_MSG_NOTSUP, |
---|
64 | IPC_MSG_PEX, |
---|
65 | IPC_MSG_PORT, |
---|
66 | IPC_MSG_QUIT, |
---|
67 | IPC_MSG_REMOVE, |
---|
68 | IPC_MSG_REMOVEALL, |
---|
69 | IPC_MSG_START, |
---|
70 | IPC_MSG_STARTALL, |
---|
71 | IPC_MSG_STAT, |
---|
72 | IPC_MSG_STOP, |
---|
73 | IPC_MSG_STOPALL, |
---|
74 | IPC_MSG_OK, |
---|
75 | IPC_MSG_SUP, |
---|
76 | IPC_MSG_UPLIMIT, |
---|
77 | IPC_MSG_VERSION, |
---|
78 | IPC__MSG_COUNT |
---|
79 | }; |
---|
80 | |
---|
81 | #define IPC_INF_COMMENT ( 1 << 0 ) |
---|
82 | #define IPC_INF_CREATOR ( 1 << 1 ) |
---|
83 | #define IPC_INF_DATE ( 1 << 2 ) |
---|
84 | #define IPC_INF_FILES ( 1 << 3 ) |
---|
85 | #define IPC_INF_HASH ( 1 << 4 ) |
---|
86 | #define IPC_INF_ID ( 1 << 5 ) |
---|
87 | #define IPC_INF_NAME ( 1 << 6 ) |
---|
88 | #define IPC_INF_PATH ( 1 << 7 ) |
---|
89 | #define IPC_INF_PRIVATE ( 1 << 8 ) |
---|
90 | #define IPC_INF_SAVED ( 1 << 9 ) |
---|
91 | #define IPC_INF_SIZE ( 1 << 10 ) |
---|
92 | #define IPC_INF_TRACKERS ( 1 << 11 ) |
---|
93 | #define IPC_INF__MAX ( 1 << 12 ) |
---|
94 | |
---|
95 | #define IPC_ST_COMPLETED ( 1 << 0 ) |
---|
96 | #define IPC_ST_DOWNSPEED ( 1 << 1 ) |
---|
97 | #define IPC_ST_DOWNTOTAL ( 1 << 2 ) |
---|
98 | #define IPC_ST_DOWNVALID ( 1 << 3 ) |
---|
99 | #define IPC_ST_ERROR ( 1 << 4 ) |
---|
100 | #define IPC_ST_ERRMSG ( 1 << 5 ) |
---|
101 | #define IPC_ST_ETA ( 1 << 6 ) |
---|
102 | #define IPC_ST_ID ( 1 << 7 ) |
---|
103 | #define IPC_ST_PEERDOWN ( 1 << 8 ) |
---|
104 | #define IPC_ST_PEERFROM ( 1 << 9 ) |
---|
105 | #define IPC_ST_PEERTOTAL ( 1 << 10 ) |
---|
106 | #define IPC_ST_PEERUP ( 1 << 11 ) |
---|
107 | #define IPC_ST_RUNNING ( 1 << 12 ) |
---|
108 | #define IPC_ST_STATE ( 1 << 13 ) |
---|
109 | #define IPC_ST_SWARM ( 1 << 14 ) |
---|
110 | #define IPC_ST_TRACKER ( 1 << 15 ) |
---|
111 | #define IPC_ST_TKDONE ( 1 << 16 ) |
---|
112 | #define IPC_ST_TKLEECH ( 1 << 17 ) |
---|
113 | #define IPC_ST_TKSEED ( 1 << 18 ) |
---|
114 | #define IPC_ST_UPSPEED ( 1 << 19 ) |
---|
115 | #define IPC_ST_UPTOTAL ( 1 << 20 ) |
---|
116 | #define IPC_ST__MAX ( 1 << 21 ) |
---|
117 | |
---|
118 | struct ipc_funcs; |
---|
119 | struct ipc_info; |
---|
120 | struct strlist; |
---|
121 | |
---|
122 | struct ipc_info |
---|
123 | { |
---|
124 | struct ipc_funcs * funcs; |
---|
125 | int vers; |
---|
126 | char * label; |
---|
127 | }; |
---|
128 | |
---|
129 | #define HASVERS( info ) ( 0 < (info)->vers ) |
---|
130 | #define VERSLABEL( info ) ( (info)->label ) |
---|
131 | |
---|
132 | #define TORRENT_ID_VALID( id ) ( 0 < (id) && INT_MAX > (id) ) |
---|
133 | |
---|
134 | typedef void ( *trd_msgfunc )( enum ipc_msg, benc_val_t *, int64_t, void * ); |
---|
135 | |
---|
136 | /* any of these functions that can fail may set errno for any of the |
---|
137 | errors set by malloc() or calloc() */ |
---|
138 | |
---|
139 | /* setup */ |
---|
140 | struct ipc_funcs * ipc_initmsgs ( void ); |
---|
141 | int ipc_addmsg ( struct ipc_funcs *, enum ipc_msg, trd_msgfunc ); |
---|
142 | void ipc_setdefmsg( struct ipc_funcs *, trd_msgfunc ); |
---|
143 | void ipc_freemsgs ( struct ipc_funcs * ); |
---|
144 | struct ipc_info * ipc_newcon( struct ipc_funcs * ); |
---|
145 | void ipc_freecon ( struct ipc_info * ); |
---|
146 | |
---|
147 | /* message creation */ |
---|
148 | /* sets errno to EPERM if requested message not supported by protocol vers */ |
---|
149 | benc_val_t * ipc_initval ( struct ipc_info *, enum ipc_msg, int64_t, |
---|
150 | benc_val_t *, int ); |
---|
151 | uint8_t * ipc_mkval ( benc_val_t *, size_t * ); |
---|
152 | uint8_t * ipc_mkempty ( struct ipc_info *, size_t *, enum ipc_msg, |
---|
153 | int64_t ); |
---|
154 | uint8_t * ipc_mkint ( struct ipc_info *, size_t *, enum ipc_msg, int64_t, |
---|
155 | int64_t ); |
---|
156 | uint8_t * ipc_mkstr ( struct ipc_info *, size_t *, enum ipc_msg, int64_t, |
---|
157 | const char * ); |
---|
158 | uint8_t * ipc_mkvers ( size_t *, const char * ); |
---|
159 | uint8_t * ipc_mkgetinfo( struct ipc_info *, size_t *, enum ipc_msg, int64_t, |
---|
160 | int, const int * ); |
---|
161 | int ipc_addinfo ( benc_val_t *, int, tr_info_t *, int ); |
---|
162 | int ipc_addstat ( benc_val_t *, int, const tr_stat_t *, int ); |
---|
163 | |
---|
164 | /* sets errno to EINVAL on parse error or |
---|
165 | EPERM for unsupported protocol version */ |
---|
166 | ssize_t ipc_parse ( struct ipc_info *, uint8_t *, ssize_t, void * ); |
---|
167 | |
---|
168 | /* misc info functions, these will always succeed */ |
---|
169 | int ipc_havemsg ( struct ipc_info *, enum ipc_msg ); |
---|
170 | enum ipc_msg ipc_msgid ( struct ipc_info *, const char * ); |
---|
171 | int ipc_ishandled( struct ipc_info *, enum ipc_msg ); |
---|
172 | int ipc_havetags ( struct ipc_info * ); |
---|
173 | int ipc_infotypes( enum ipc_msg, benc_val_t * ); |
---|
174 | const char * ipc_infoname ( enum ipc_msg, int ); |
---|
175 | |
---|
176 | #endif /* TR_DAEMON_IPC_H */ |
---|