2007-04-18 16:39:10 +00:00
|
|
|
/******************************************************************************
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-01-01 17:20:20 +00:00
|
|
|
* Copyright (c) 2007-2008 Joshua Elsasser
|
2007-04-18 16:39:10 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef TR_DAEMON_IPC_H
|
|
|
|
#define TR_DAEMON_IPC_H
|
|
|
|
|
2007-06-14 11:41:09 +00:00
|
|
|
#include <inttypes.h>
|
2008-01-01 17:01:18 +00:00
|
|
|
#include <unistd.h> /* for ssize_t */
|
2007-04-18 16:39:10 +00:00
|
|
|
|
|
|
|
#define IPC_MIN_MSG_LEN ( 8 )
|
|
|
|
#define IPC_MAX_MSG_LEN ( 0x7fffffff - IPC_MIN_MSG_LEN )
|
|
|
|
|
2008-02-27 06:01:46 +00:00
|
|
|
/* These need to be in the same order as ipcparse.c's gl_msgs array. */
|
2007-04-18 16:39:10 +00:00
|
|
|
enum ipc_msg
|
|
|
|
{
|
2008-02-27 06:01:46 +00:00
|
|
|
IPC_MSG_ADDONEFILE = 0,
|
|
|
|
IPC_MSG_ADDMANYFILES,
|
2007-04-18 16:39:10 +00:00
|
|
|
IPC_MSG_AUTOMAP,
|
|
|
|
IPC_MSG_AUTOSTART,
|
2007-06-10 20:31:52 +00:00
|
|
|
IPC_MSG_BAD,
|
2007-04-18 16:39:10 +00:00
|
|
|
IPC_MSG_DIR,
|
|
|
|
IPC_MSG_DOWNLIMIT,
|
2008-02-27 06:01:46 +00:00
|
|
|
IPC_MSG_CRYPTO,
|
2007-04-18 16:39:10 +00:00
|
|
|
IPC_MSG_FAIL,
|
|
|
|
IPC_MSG_GETAUTOMAP,
|
|
|
|
IPC_MSG_GETAUTOSTART,
|
|
|
|
IPC_MSG_GETDIR,
|
|
|
|
IPC_MSG_GETDOWNLIMIT,
|
2008-02-27 06:01:46 +00:00
|
|
|
IPC_MSG_GETCRYPTO,
|
2007-04-18 16:39:10 +00:00
|
|
|
IPC_MSG_GETINFO,
|
|
|
|
IPC_MSG_GETINFOALL,
|
|
|
|
IPC_MSG_GETPEX,
|
|
|
|
IPC_MSG_GETPORT,
|
|
|
|
IPC_MSG_GETSTAT,
|
|
|
|
IPC_MSG_GETSTATALL,
|
|
|
|
IPC_MSG_GETSUP,
|
|
|
|
IPC_MSG_GETUPLIMIT,
|
|
|
|
IPC_MSG_INFO,
|
2008-02-27 06:01:46 +00:00
|
|
|
IPC_MSG_LOOKUP,
|
2007-04-18 16:39:10 +00:00
|
|
|
IPC_MSG_NOOP,
|
|
|
|
IPC_MSG_NOTSUP,
|
2008-04-06 17:12:15 +00:00
|
|
|
IPC_MSG_PEERMAX,
|
2007-04-18 16:39:10 +00:00
|
|
|
IPC_MSG_PEX,
|
|
|
|
IPC_MSG_PORT,
|
|
|
|
IPC_MSG_QUIT,
|
|
|
|
IPC_MSG_REMOVE,
|
|
|
|
IPC_MSG_REMOVEALL,
|
|
|
|
IPC_MSG_START,
|
|
|
|
IPC_MSG_STARTALL,
|
|
|
|
IPC_MSG_STAT,
|
|
|
|
IPC_MSG_STOP,
|
|
|
|
IPC_MSG_STOPALL,
|
|
|
|
IPC_MSG_OK,
|
|
|
|
IPC_MSG_SUP,
|
|
|
|
IPC_MSG_UPLIMIT,
|
2008-02-27 17:38:39 +00:00
|
|
|
IPC_MSG_VERIFY,
|
2007-04-18 16:39:10 +00:00
|
|
|
IPC_MSG_VERSION,
|
2007-07-14 05:29:18 +00:00
|
|
|
IPC__MSG_COUNT,
|
|
|
|
IPC__MSG_UNKNOWN
|
2007-04-18 16:39:10 +00:00
|
|
|
};
|
|
|
|
|
2008-02-27 06:01:46 +00:00
|
|
|
/* If you add or delete a constant here, to renumber the ones after it.
|
|
|
|
* They need to be in ascending order starting at zero, with no gaps.
|
|
|
|
* They also need to be in the same order as ipcparse.c's gl_inf array. */
|
2007-04-18 16:39:10 +00:00
|
|
|
#define IPC_INF_COMMENT ( 1 << 0 )
|
|
|
|
#define IPC_INF_CREATOR ( 1 << 1 )
|
|
|
|
#define IPC_INF_DATE ( 1 << 2 )
|
|
|
|
#define IPC_INF_FILES ( 1 << 3 )
|
|
|
|
#define IPC_INF_HASH ( 1 << 4 )
|
|
|
|
#define IPC_INF_ID ( 1 << 5 )
|
|
|
|
#define IPC_INF_NAME ( 1 << 6 )
|
|
|
|
#define IPC_INF_PATH ( 1 << 7 )
|
|
|
|
#define IPC_INF_PRIVATE ( 1 << 8 )
|
2007-10-26 00:57:29 +00:00
|
|
|
#define IPC_INF_SIZE ( 1 << 9 )
|
|
|
|
#define IPC_INF_TRACKERS ( 1 << 10 )
|
|
|
|
#define IPC_INF__MAX ( 1 << 11 )
|
2007-04-18 16:39:10 +00:00
|
|
|
|
2008-02-27 06:01:46 +00:00
|
|
|
/* If you add or delete a constant here, to renumber the ones after it.
|
|
|
|
* They need to be in ascending order starting at zero, with no gaps.
|
|
|
|
* They also need to be in the same order as ipcparse.c's gl_stat array. */
|
2007-04-18 16:39:10 +00:00
|
|
|
#define IPC_ST_COMPLETED ( 1 << 0 )
|
|
|
|
#define IPC_ST_DOWNSPEED ( 1 << 1 )
|
|
|
|
#define IPC_ST_DOWNTOTAL ( 1 << 2 )
|
2007-06-26 17:52:45 +00:00
|
|
|
#define IPC_ST_DOWNVALID ( 1 << 3 )
|
|
|
|
#define IPC_ST_ERROR ( 1 << 4 )
|
|
|
|
#define IPC_ST_ERRMSG ( 1 << 5 )
|
|
|
|
#define IPC_ST_ETA ( 1 << 6 )
|
|
|
|
#define IPC_ST_ID ( 1 << 7 )
|
|
|
|
#define IPC_ST_PEERDOWN ( 1 << 8 )
|
|
|
|
#define IPC_ST_PEERFROM ( 1 << 9 )
|
2008-04-06 17:12:15 +00:00
|
|
|
#define IPC_ST_PEERMAX ( 1 << 10 )
|
|
|
|
#define IPC_ST_PEERTOTAL ( 1 << 11 )
|
|
|
|
#define IPC_ST_PEERUP ( 1 << 12 )
|
|
|
|
#define IPC_ST_RUNNING ( 1 << 13 )
|
|
|
|
#define IPC_ST_TKDONE ( 1 << 14 )
|
|
|
|
#define IPC_ST_TKLEECH ( 1 << 15 )
|
|
|
|
#define IPC_ST_TKSEED ( 1 << 16 )
|
|
|
|
#define IPC_ST_STATE ( 1 << 17 )
|
|
|
|
#define IPC_ST_SWARM ( 1 << 18 )
|
|
|
|
#define IPC_ST_TRACKER ( 1 << 19 )
|
|
|
|
#define IPC_ST_UPSPEED ( 1 << 20 )
|
|
|
|
#define IPC_ST_UPTOTAL ( 1 << 21 )
|
|
|
|
#define IPC_ST__MAX ( 1 << 22 )
|
2007-04-18 16:39:10 +00:00
|
|
|
|
|
|
|
struct ipc_funcs;
|
|
|
|
struct ipc_info;
|
2008-02-26 21:58:58 +00:00
|
|
|
struct tr_info;
|
|
|
|
struct tr_benc;
|
|
|
|
struct tr_stat;
|
2007-04-18 16:39:10 +00:00
|
|
|
|
|
|
|
|
2008-02-27 16:47:58 +00:00
|
|
|
#define TORRENT_ID_VALID( id ) ( ( 0 < (id) ) && ( (id) < INT_MAX ) )
|
2007-05-24 07:11:59 +00:00
|
|
|
|
2008-02-27 16:47:58 +00:00
|
|
|
typedef void ( *trd_msgfunc )( enum ipc_msg msg_id,
|
|
|
|
struct tr_benc * benc,
|
|
|
|
int64_t tag,
|
|
|
|
void * arg );
|
2007-04-18 16:39:10 +00:00
|
|
|
|
|
|
|
/* any of these functions that can fail may set errno for any of the
|
|
|
|
errors set by malloc() or calloc() */
|
|
|
|
|
|
|
|
/* setup */
|
|
|
|
struct ipc_funcs * ipc_initmsgs ( void );
|
2008-02-27 16:47:58 +00:00
|
|
|
void ipc_addmsg ( struct ipc_funcs *, enum ipc_msg,
|
|
|
|
trd_msgfunc );
|
2008-02-27 08:07:13 +00:00
|
|
|
void ipc_setdefmsg( struct ipc_funcs *, trd_msgfunc );
|
|
|
|
void ipc_freemsgs ( struct ipc_funcs * );
|
|
|
|
struct ipc_info * ipc_newcon ( struct ipc_funcs * );
|
|
|
|
void ipc_freecon ( struct ipc_info * );
|
2008-02-27 16:47:58 +00:00
|
|
|
int ipc_hasvers ( const struct ipc_info * );
|
2007-04-18 16:39:10 +00:00
|
|
|
|
|
|
|
/* message creation */
|
|
|
|
/* sets errno to EPERM if requested message not supported by protocol vers */
|
2008-02-27 16:47:58 +00:00
|
|
|
struct tr_benc * ipc_initval ( const struct ipc_info *, enum ipc_msg,
|
|
|
|
int64_t tag, struct tr_benc *, int );
|
2008-04-03 21:38:32 +00:00
|
|
|
uint8_t * ipc_serialize ( const struct tr_benc *, size_t * );
|
|
|
|
uint8_t * ipc_mkempty ( const struct ipc_info *, size_t *, enum ipc_msg,
|
|
|
|
int64_t );
|
|
|
|
uint8_t * ipc_mkint ( const struct ipc_info *, size_t *, enum ipc_msg,
|
|
|
|
int64_t tag, int64_t val );
|
|
|
|
uint8_t * ipc_mkstr ( const struct ipc_info *, size_t *, enum ipc_msg,
|
|
|
|
int64_t tag, const char * val );
|
|
|
|
uint8_t * ipc_mkvers ( size_t *, const char * );
|
2008-04-04 17:19:44 +00:00
|
|
|
|
|
|
|
uint8_t * ipc_createInfoRequest( const struct ipc_info * session,
|
|
|
|
size_t * setme_len,
|
|
|
|
enum ipc_msg msg_id,
|
|
|
|
int64_t tag,
|
|
|
|
int types,
|
|
|
|
const int * ids );
|
|
|
|
|
2008-04-03 21:38:32 +00:00
|
|
|
int ipc_addinfo ( struct tr_benc *, int,
|
|
|
|
const struct tr_info *, int );
|
2008-04-06 17:12:15 +00:00
|
|
|
|
|
|
|
struct tr_torrent;
|
|
|
|
|
|
|
|
int ipc_addstat ( struct tr_benc * appendme_list,
|
|
|
|
int torrent_id,
|
|
|
|
struct tr_torrent * tor,
|
|
|
|
int stat_types );
|
2007-04-18 16:39:10 +00:00
|
|
|
|
|
|
|
/* sets errno to EINVAL on parse error or
|
|
|
|
EPERM for unsupported protocol version */
|
2008-04-04 17:19:44 +00:00
|
|
|
ssize_t ipc_handleMessages( struct ipc_info * session,
|
|
|
|
const uint8_t * serializedMessages ,
|
|
|
|
ssize_t serializedLength,
|
|
|
|
void * user_data );
|
2007-04-18 16:39:10 +00:00
|
|
|
|
|
|
|
/* misc info functions, these will always succeed */
|
2008-02-27 16:47:58 +00:00
|
|
|
enum ipc_msg ipc_msgid ( const struct ipc_info *, const char * );
|
|
|
|
int ipc_ishandled( const struct ipc_info *, enum ipc_msg );
|
|
|
|
int ipc_havetags ( const struct ipc_info * );
|
2008-02-27 06:01:46 +00:00
|
|
|
int ipc_infotypes( enum ipc_msg, const struct tr_benc * );
|
2007-04-18 16:39:10 +00:00
|
|
|
const char * ipc_infoname ( enum ipc_msg, int );
|
|
|
|
|
|
|
|
#endif /* TR_DAEMON_IPC_H */
|