source: trunk/libtransmission/ipcparse.h @ 5142

Last change on this file since 5142 was 5142, checked in by charles, 14 years ago

make struct ipc_info opaque. const-ify the ipcparse functions where possible.

  • Property svn:keywords set to Date Rev Author Id
File size: 6.9 KB
Line 
1/******************************************************************************
2 * $Id: ipcparse.h 5142 2008-02-27 16:47:58Z charles $
3 *
4 * Copyright (c) 2007-2008 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#include <unistd.h> /* for ssize_t */
30
31#define IPC_MIN_MSG_LEN         ( 8 )
32#define IPC_MAX_MSG_LEN         ( 0x7fffffff - IPC_MIN_MSG_LEN )
33
34/* These need to be in the same order as ipcparse.c's gl_msgs array. */
35enum ipc_msg
36{
37    IPC_MSG_ADDONEFILE = 0,
38    IPC_MSG_ADDMANYFILES,
39    IPC_MSG_AUTOMAP,
40    IPC_MSG_AUTOSTART,
41    IPC_MSG_BAD,
42    IPC_MSG_DIR,
43    IPC_MSG_DOWNLIMIT,
44    IPC_MSG_CRYPTO,
45    IPC_MSG_FAIL,
46    IPC_MSG_GETAUTOMAP,
47    IPC_MSG_GETAUTOSTART,
48    IPC_MSG_GETDIR,
49    IPC_MSG_GETDOWNLIMIT,
50    IPC_MSG_GETCRYPTO,
51    IPC_MSG_GETINFO,
52    IPC_MSG_GETINFOALL,
53    IPC_MSG_GETPEX,
54    IPC_MSG_GETPORT,
55    IPC_MSG_GETSTAT,
56    IPC_MSG_GETSTATALL,
57    IPC_MSG_GETSUP,
58    IPC_MSG_GETUPLIMIT,
59    IPC_MSG_INFO,
60    IPC_MSG_LOOKUP,
61    IPC_MSG_NOOP,
62    IPC_MSG_NOTSUP,
63    IPC_MSG_PEX,
64    IPC_MSG_PORT,
65    IPC_MSG_QUIT,
66    IPC_MSG_REMOVE,
67    IPC_MSG_REMOVEALL,
68    IPC_MSG_START,
69    IPC_MSG_STARTALL,
70    IPC_MSG_STAT,
71    IPC_MSG_STOP,
72    IPC_MSG_STOPALL,
73    IPC_MSG_OK,
74    IPC_MSG_SUP,
75    IPC_MSG_UPLIMIT,
76    IPC_MSG_VERSION,
77    IPC__MSG_COUNT,
78    IPC__MSG_UNKNOWN
79};
80
81/* If you add or delete a constant here, to renumber the ones after it.
82 * They need to be in ascending order starting at zero, with no gaps.
83 * They also need to be in the same order as ipcparse.c's gl_inf array. */
84#define IPC_INF_COMMENT         ( 1 << 0 )
85#define IPC_INF_CREATOR         ( 1 << 1 )
86#define IPC_INF_DATE            ( 1 << 2 )
87#define IPC_INF_FILES           ( 1 << 3 )
88#define IPC_INF_HASH            ( 1 << 4 )
89#define IPC_INF_ID              ( 1 << 5 )
90#define IPC_INF_NAME            ( 1 << 6 )
91#define IPC_INF_PATH            ( 1 << 7 )
92#define IPC_INF_PRIVATE         ( 1 << 8 )
93#define IPC_INF_SIZE            ( 1 << 9 )
94#define IPC_INF_TRACKERS        ( 1 << 10 )
95#define IPC_INF__MAX            ( 1 << 11 )
96
97/* If you add or delete a constant here, to renumber the ones after it.
98 * They need to be in ascending order starting at zero, with no gaps.
99 * They also need to be in the same order as ipcparse.c's gl_stat array. */
100#define IPC_ST_COMPLETED        ( 1 << 0 )
101#define IPC_ST_DOWNSPEED        ( 1 << 1 )
102#define IPC_ST_DOWNTOTAL        ( 1 << 2 )
103#define IPC_ST_DOWNVALID        ( 1 << 3 )
104#define IPC_ST_ERROR            ( 1 << 4 )
105#define IPC_ST_ERRMSG           ( 1 << 5 )
106#define IPC_ST_ETA              ( 1 << 6 )
107#define IPC_ST_ID               ( 1 << 7 )
108#define IPC_ST_PEERDOWN         ( 1 << 8 )
109#define IPC_ST_PEERFROM         ( 1 << 9 )
110#define IPC_ST_PEERTOTAL        ( 1 << 10 )
111#define IPC_ST_PEERUP           ( 1 << 11 )
112#define IPC_ST_RUNNING          ( 1 << 12 )
113#define IPC_ST_TKDONE           ( 1 << 13 )
114#define IPC_ST_TKLEECH          ( 1 << 14 )
115#define IPC_ST_TKSEED           ( 1 << 15 )
116#define IPC_ST_STATE            ( 1 << 16 )
117#define IPC_ST_SWARM            ( 1 << 17 )
118#define IPC_ST_TRACKER          ( 1 << 18 )
119#define IPC_ST_UPSPEED          ( 1 << 19 )
120#define IPC_ST_UPTOTAL          ( 1 << 20 )
121#define IPC_ST__MAX             ( 1 << 21 )
122
123struct ipc_funcs;
124struct ipc_info;
125struct tr_info;
126struct tr_benc;
127struct tr_stat;
128
129
130#define TORRENT_ID_VALID( id )  ( ( 0 < (id) ) && ( (id) < INT_MAX ) )
131
132typedef void ( *trd_msgfunc )( enum ipc_msg      msg_id,
133                               struct tr_benc  * benc,
134                               int64_t           tag,
135                               void            * arg );
136
137/* any of these functions that can fail may set errno for any of the
138   errors set by malloc() or calloc() */
139
140/* setup */
141struct ipc_funcs * ipc_initmsgs ( void );
142void               ipc_addmsg   ( struct ipc_funcs *, enum ipc_msg,
143                                  trd_msgfunc );
144void               ipc_setdefmsg( struct ipc_funcs *, trd_msgfunc );
145void               ipc_freemsgs ( struct ipc_funcs * );
146struct ipc_info *  ipc_newcon   ( struct ipc_funcs * );
147void               ipc_freecon  ( struct ipc_info * );
148int                ipc_hasvers  ( const struct ipc_info * );
149
150/* message creation */
151/* sets errno to EPERM if requested message not supported by protocol vers */
152struct tr_benc * ipc_initval  ( const struct ipc_info *, enum ipc_msg,
153                                int64_t tag, struct tr_benc *, int );
154uint8_t *    ipc_mkval    ( const struct tr_benc *, size_t * );
155uint8_t *    ipc_mkempty  ( const struct ipc_info *, size_t *, enum ipc_msg,
156                            int64_t );
157uint8_t *    ipc_mkint    ( const struct ipc_info *, size_t *, enum ipc_msg,
158                            int64_t tag, int64_t val );
159uint8_t *    ipc_mkstr    ( const struct ipc_info *, size_t *, enum ipc_msg,
160                            int64_t tag, const char * val );
161uint8_t *    ipc_mkvers   ( size_t *, const char * );
162uint8_t *    ipc_mkgetinfo( const struct ipc_info *, size_t *, enum ipc_msg,
163                            int64_t, int, const int * );
164int          ipc_addinfo  ( struct tr_benc *, int,
165                            const struct tr_info *, int );
166int          ipc_addstat  ( struct tr_benc *, int,
167                            const struct tr_stat *, int );
168
169/* sets errno to EINVAL on parse error or
170   EPERM for unsupported protocol version */
171ssize_t      ipc_parse    ( struct ipc_info *, const uint8_t *,
172                            ssize_t, void * );
173
174/* misc info functions, these will always succeed */
175enum ipc_msg ipc_msgid    ( const struct ipc_info *, const char * );
176int          ipc_ishandled( const struct ipc_info *, enum ipc_msg );
177int          ipc_havetags ( const struct ipc_info * );
178int          ipc_infotypes( enum ipc_msg, const struct tr_benc * );
179const char * ipc_infoname ( enum ipc_msg, int );
180
181#endif /* TR_DAEMON_IPC_H */
Note: See TracBrowser for help on using the repository browser.