File: xfer.h

package info (click to toggle)
pidgin-nateon 0.0.0.svn147-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, jessie, jessie-kfreebsd, sid, stretch, wheezy
  • size: 2,616 kB
  • ctags: 779
  • sloc: sh: 9,081; ansic: 6,639; makefile: 110
file content (148 lines) | stat: -rw-r--r-- 3,897 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
 * @file xfer.h NATEON file transfer functions
 * @ingroup nateon 
 *
 * purple
 *
 * Purple is the legal property of its developers, whose names are too numerous
 * to list here.  Please refer to the COPYRIGHT file distributed with this
 * source distribution.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
#ifndef _NATEON_XFER_H_
#define _NATEON_XFER_H_

#include "libpurple/network.h"

#define NATEON_XFER_SEND_BUFFER_SIZE	(8191)

typedef struct _NateonXfer NateonXfer;
typedef struct _NateonXferConnection NateonXferConnection;

/**
 * P2P Connection for file transfer.
 */
struct _NateonXferConnection {
	int fd;		/**< socket file descriptor */

	int rx_pa;		/**< socket read watcher */
	char *rx_buf;	/**< The receive buffer. */
	int rx_len;		/**< The receive buffer length. */

	PurpleCircBuffer *tx_buf;
	gint tx_handler;

	int inpa;

	NateonXfer *nate_xfer;
};

typedef enum
{
	NATEON_XFER_CONN_NONE,
	NATEON_XFER_CONN_P2P,
	NATEON_XFER_CONN_FR
} NateonXferConnType;

typedef enum
{
    NATEON_XFER_CONTENT_FILE,
    NATEON_XFER_CONTENT_BUDDYIMG
} NateonXferContentType;

/**
 * File Transfer.
 */
struct _NateonXfer
{
	NateonSession *session; /**< The NATEON session of this file transfer */
	NateonSwitchBoard *swboard;

	PurpleXfer *prpl_xfer;

	char *who;	/**< peer's account name */
	char *my_ip;

    NateonXferConnType content_type;

	/* P2P related */
	PurpleNetworkListenData	*p2p_listen_data;
	PurpleProxyConnectData	*p2p_connect_data;
	int		p2p_listen_pa;		/**< listen port watcher */
	int		p2p_listen_fd;
	char	*p2p_cookie;
	int		p2p_listen_port;	/**< listening port number */
	guint	p2p_timer;

	/* FR-server related */
	int fr_initiate_trid;
	char *fr_ip;
	int fr_port;
	char *fr_authkey;
	PurpleProxyConnectData *fr_connect_data;

	char *file_cookie;	/**< cookie of the file transferred */
	FILE *dest_fp;

	NateonXferConnType conntype;

	NateonXferConnection conn;

	gboolean chunk_processing;
	int chunk_cur_len;
	int chunk_len;

	int recv_len;

	FILE *local_fp;
	char send_buf[NATEON_XFER_SEND_BUFFER_SIZE];
	int send_data_trid;
	int sent_len;
};

/**
 * Start File-receive process.
 *
 * @param session Nateon Session
 * @param who file sender account
 * @param filename filename
 * @param filesize size of the file receiving
 * @param cookie file cookie
 */
void nateon_xfer_receive_file(NateonSession *session, NateonSwitchBoard *swboard, \
		const char *who, const char *filename, const int filesize, const char *cookie);

/**
 * Start File-send process.
 *
 * @param session Nateon Session
 * @param who file receiver account
 * @param filename filename
 */
void nateon_xfer_send_file(NateonSession *session, const char *who, const char *filename);

void nateon_xfer_parse_reqc(NateonSession *session, NateonCmdProc *cmdproc, char **params, \
								int param_count);

void nateon_xfer_parse_refr(NateonSession *session, char **params, int param_count);

void nateon_xfer_cancel_transfer(NateonSession *session, const char *who, const char *filename,\
									const char *cookie);

void nateon_xfer_receive_buddyimage(NateonSession *session, NateonSwitchBoard *swboard, \
		const char *who, const char *uniq_name, const int filesize, const char *cookie);

#endif /* _NATEON_XFER_H_ */