Thu, 04 Jul 2019 20:38:04 -0500
Cleanups from review
| 8351 | 1 | /** |
| 2 | * @file dcc_send.c Functions used in sending files with DCC SEND | |
| 3 | * | |
| 15884 | 4 | * purple |
| 8351 | 5 | * |
| 6 | * Copyright (C) 2004, Timothy T Ringenbach <omarvo@hotmail.com> | |
| 15884 | 7 | * Copyright (C) 2003, Robbert Haarman <purple@inglorion.net> |
| 8351 | 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify | |
| 10 | * it under the terms of the GNU General Public License as published by | |
| 11 | * the Free Software Foundation; either version 2 of the License, or | |
| 12 | * (at your option) any later version. | |
| 13 | * | |
| 14 | * This program is distributed in the hope that it will be useful, | |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 17 | * GNU General Public License for more details. | |
| 18 | * | |
| 19 | * You should have received a copy of the GNU General Public License | |
| 20 | * along with this program; if not, write to the Free Software | |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
15884
diff
changeset
|
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
| 8351 | 22 | */ |
| 23 | ||
| 24 | #include "internal.h" | |
| 25 | #include "irc.h" | |
| 26 | #include "debug.h" | |
|
34910
60502558e400
Replacements for the GObject Xfer API
Ankit Vani <a@nevitus.org>
parents:
32702
diff
changeset
|
27 | #include "xfer.h" |
| 8351 | 28 | #include "notify.h" |
| 29 | #include "network.h" | |
| 30 | ||
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
31 | struct _IrcXfer { |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
32 | PurpleXfer parent; |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
33 | |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
34 | /* receive properties */ |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
35 | gchar *ip; |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
36 | guint remote_port; |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
37 | |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
38 | /* send properties */ |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
39 | PurpleNetworkListenData *listen_data; |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
40 | gint inpa; |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
41 | gint fd; |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
42 | guchar *rxqueue; |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
43 | guint rxlen; |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
44 | }; |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
45 | |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
46 | G_DEFINE_DYNAMIC_TYPE(IrcXfer, irc_xfer, PURPLE_TYPE_XFER); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
47 | |
| 8351 | 48 | /*************************************************************************** |
| 49 | * Functions related to receiving files via DCC SEND | |
| 50 | ***************************************************************************/ | |
| 51 | ||
| 52 | /* | |
| 53 | * This function is called whenever data is received. | |
| 54 | * It sends the acknowledgement (in the form of a total byte count as an | |
| 55 | * unsigned 4 byte integer in network byte order) | |
| 56 | */ | |
| 15884 | 57 | static void irc_dccsend_recv_ack(PurpleXfer *xfer, const guchar *data, size_t size) { |
|
27472
68b65e95f436
Don't send 64-bit DCC application-level acknowledgments on 64-bit systems.
Ethan Blanton <elb@pidgin.im>
parents:
24763
diff
changeset
|
58 | guint32 l; |
|
32270
028a4b3c0402
Steps toward hiding PurpleXfer.
Daniel Atallah <datallah@pidgin.im>
parents:
32242
diff
changeset
|
59 | gssize result; |
| 8351 | 60 | |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
61 | if(purple_xfer_get_xfer_type(xfer) != PURPLE_XFER_TYPE_RECEIVE) { |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
62 | return; |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
63 | } |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
64 | |
|
32270
028a4b3c0402
Steps toward hiding PurpleXfer.
Daniel Atallah <datallah@pidgin.im>
parents:
32242
diff
changeset
|
65 | l = htonl(purple_xfer_get_bytes_sent(xfer)); |
|
028a4b3c0402
Steps toward hiding PurpleXfer.
Daniel Atallah <datallah@pidgin.im>
parents:
32242
diff
changeset
|
66 | result = purple_xfer_write(xfer, (guchar *)&l, sizeof(l)); |
|
22196
5f46b63e2c0d
Part of a large patch from o_sukhodolsky to fix some build warnings.
Richard Laager <rlaager@pidgin.im>
parents:
21676
diff
changeset
|
67 | if (result != sizeof(l)) { |
|
22257
dd49963fe3f6
Use g_strerror() instead of strerror() in a few places.
Richard Laager <rlaager@pidgin.im>
parents:
22196
diff
changeset
|
68 | purple_debug_error("irc", "unable to send acknowledgement: %s\n", g_strerror(errno)); |
|
22196
5f46b63e2c0d
Part of a large patch from o_sukhodolsky to fix some build warnings.
Richard Laager <rlaager@pidgin.im>
parents:
21676
diff
changeset
|
69 | /* TODO: We should probably close the connection here or something. */ |
|
5f46b63e2c0d
Part of a large patch from o_sukhodolsky to fix some build warnings.
Richard Laager <rlaager@pidgin.im>
parents:
21676
diff
changeset
|
70 | } |
| 8351 | 71 | } |
| 72 | ||
| 15884 | 73 | static void irc_dccsend_recv_init(PurpleXfer *xfer) { |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
74 | IrcXfer *xd = IRC_XFER(xfer); |
| 8351 | 75 | |
|
32270
028a4b3c0402
Steps toward hiding PurpleXfer.
Daniel Atallah <datallah@pidgin.im>
parents:
32242
diff
changeset
|
76 | purple_xfer_start(xfer, -1, xd->ip, xd->remote_port); |
| 8351 | 77 | } |
| 78 | ||
| 79 | /* This function makes the necessary arrangements for receiving files */ | |
| 80 | void irc_dccsend_recv(struct irc_conn *irc, const char *from, const char *msg) { | |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
81 | IrcXfer *xfer; |
| 8351 | 82 | gchar **token; |
| 83 | struct in_addr addr; | |
| 84 | GString *filename; | |
| 85 | int i = 0; | |
| 86 | guint32 nip; | |
| 87 | ||
| 88 | token = g_strsplit(msg, " ", 0); | |
| 89 | if (!token[0] || !token[1] || !token[2]) { | |
| 90 | g_strfreev(token); | |
| 91 | return; | |
| 92 | } | |
| 93 | ||
| 94 | filename = g_string_new(""); | |
| 95 | if (token[0][0] == '"') { | |
| 96 | if (!strchr(&(token[0][1]), '"')) { | |
| 97 | g_string_append(filename, &(token[0][1])); | |
| 98 | for (i = 1; token[i]; i++) | |
| 99 | if (!strchr(token[i], '"')) { | |
| 100 | g_string_append_printf(filename, " %s", token[i]); | |
| 101 | } else { | |
| 102 | g_string_append_len(filename, token[i], strlen(token[i]) - 1); | |
| 103 | break; | |
| 104 | } | |
| 105 | } else { | |
| 106 | g_string_append_len(filename, &(token[0][1]), strlen(&(token[0][1])) - 1); | |
| 107 | } | |
| 108 | } else { | |
| 109 | g_string_append(filename, token[0]); | |
| 110 | } | |
| 111 | ||
| 112 | if (!token[i] || !token[i+1] || !token[i+2]) { | |
| 113 | g_strfreev(token); | |
| 114 | g_string_free(filename, TRUE); | |
| 115 | return; | |
| 116 | } | |
| 117 | i++; | |
| 118 | ||
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
119 | xfer = g_object_new( |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
120 | IRC_TYPE_XFER, |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
121 | "account", irc->account, |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
122 | "type", PURPLE_XFER_TYPE_RECEIVE, |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
123 | "remote-user", from, |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
124 | NULL |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
125 | ); |
| 8351 | 126 | |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
127 | purple_xfer_set_filename(PURPLE_XFER(xfer), filename->str); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
128 | |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
129 | xfer->remote_port = atoi(token[i+1]); |
| 8351 | 130 | |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
131 | nip = strtoul(token[i], NULL, 10); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
132 | if (nip) { |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
133 | addr.s_addr = htonl(nip); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
134 | xfer->ip = g_strdup(inet_ntoa(addr)); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
135 | } else { |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
136 | xfer->ip = g_strdup(token[i]); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
137 | } |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
27635
diff
changeset
|
138 | |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
139 | purple_debug(PURPLE_DEBUG_INFO, "irc", "Receiving file (%s) from %s\n", |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
140 | filename->str, xfer->ip); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
141 | purple_xfer_set_size(PURPLE_XFER(xfer), token[i+2] ? atoi(token[i+2]) : 0); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
27635
diff
changeset
|
142 | |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
143 | purple_xfer_request(PURPLE_XFER(xfer)); |
|
31294
73607ab89c6f
Remove trailing whitespace
Richard Laager <rlaager@pidgin.im>
parents:
27635
diff
changeset
|
144 | |
| 8351 | 145 | g_strfreev(token); |
| 146 | g_string_free(filename, TRUE); | |
| 147 | } | |
| 148 | ||
| 149 | /******************************************************************* | |
| 150 | * Functions related to sending files via DCC SEND | |
| 151 | *******************************************************************/ | |
| 152 | ||
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
153 | /* just in case you were wondering, this is why DCC is crappy */ |
| 15884 | 154 | static void irc_dccsend_send_read(gpointer data, int source, PurpleInputCondition cond) |
| 8351 | 155 | { |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
156 | PurpleXfer *xfer = PURPLE_XFER(data); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
157 | IrcXfer *xd = IRC_XFER(xfer); |
|
22591
12cc742a8a5a
When Andrew was working on the memleak fixes, he pondered why buffer was
Ka-Hing Cheung <khc@pidgin.im>
parents:
22590
diff
changeset
|
158 | char buffer[64]; |
| 8351 | 159 | int len; |
| 160 | ||
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12909
diff
changeset
|
161 | len = read(source, buffer, sizeof(buffer)); |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12909
diff
changeset
|
162 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12909
diff
changeset
|
163 | if (len < 0 && errno == EAGAIN) |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12909
diff
changeset
|
164 | return; |
|
13788
019bc2080927
[gaim-migrate @ 16198]
Daniel Atallah <datallah@pidgin.im>
parents:
13201
diff
changeset
|
165 | else if (len <= 0) { |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12909
diff
changeset
|
166 | /* XXX: Shouldn't this be canceling the transfer? */ |
| 15884 | 167 | purple_input_remove(xd->inpa); |
| 8351 | 168 | xd->inpa = 0; |
| 169 | return; | |
| 170 | } | |
| 171 | ||
| 172 | xd->rxqueue = g_realloc(xd->rxqueue, len + xd->rxlen); | |
| 173 | memcpy(xd->rxqueue + xd->rxlen, buffer, len); | |
| 174 | xd->rxlen += len; | |
| 175 | ||
| 176 | while (1) { | |
|
35676
d9fdd45925ec
Fix some of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35029
diff
changeset
|
177 | gint32 val; |
|
11318
13fa1d5134f3
[gaim-migrate @ 13521]
Stu Tomlinson <nosnilmot@pidgin.im>
parents:
11159
diff
changeset
|
178 | size_t acked; |
| 8351 | 179 | |
| 180 | if (xd->rxlen < 4) | |
| 181 | break; | |
| 182 | ||
|
35676
d9fdd45925ec
Fix some of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35029
diff
changeset
|
183 | memcpy(&val, xd->rxqueue, sizeof(val)); |
|
d9fdd45925ec
Fix some of invalid alignment warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35029
diff
changeset
|
184 | acked = ntohl(val); |
| 8351 | 185 | |
| 186 | xd->rxlen -= 4; | |
| 187 | if (xd->rxlen) { | |
| 10388 | 188 | unsigned char *tmp = g_memdup(xd->rxqueue + 4, xd->rxlen); |
| 8351 | 189 | g_free(xd->rxqueue); |
| 190 | xd->rxqueue = tmp; | |
| 191 | } else { | |
| 192 | g_free(xd->rxqueue); | |
| 193 | xd->rxqueue = NULL; | |
| 194 | } | |
| 195 | ||
| 35029 | 196 | if ((goffset)acked >= purple_xfer_get_size(xfer)) { |
| 15884 | 197 | purple_input_remove(xd->inpa); |
| 8351 | 198 | xd->inpa = 0; |
| 15884 | 199 | purple_xfer_set_completed(xfer, TRUE); |
| 200 | purple_xfer_end(xfer); | |
| 8351 | 201 | return; |
| 202 | } | |
| 203 | } | |
| 204 | } | |
| 205 | ||
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
206 | static gssize irc_dccsend_send_write(PurpleXfer *xfer, const guchar *buffer, size_t size) |
| 8351 | 207 | { |
|
12151
8002bb57756b
[gaim-migrate @ 14452]
Richard Laager <rlaager@pidgin.im>
parents:
12143
diff
changeset
|
208 | gssize s; |
|
32270
028a4b3c0402
Steps toward hiding PurpleXfer.
Daniel Atallah <datallah@pidgin.im>
parents:
32242
diff
changeset
|
209 | gssize ret; |
| 8351 | 210 | |
| 35029 | 211 | s = MIN((gssize)purple_xfer_get_bytes_remaining(xfer), (gssize)size); |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
212 | if (!s) { |
| 8351 | 213 | return 0; |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
214 | } |
| 8351 | 215 | |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
216 | ret = PURPLE_XFER_CLASS(irc_xfer_parent_class)->write(xfer, buffer, s); |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12909
diff
changeset
|
217 | |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
218 | if (ret < 0 && errno == EAGAIN) { |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12909
diff
changeset
|
219 | ret = 0; |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
220 | } |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12909
diff
changeset
|
221 | |
|
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12909
diff
changeset
|
222 | return ret; |
| 8351 | 223 | } |
| 224 | ||
| 15884 | 225 | static void irc_dccsend_send_connected(gpointer data, int source, PurpleInputCondition cond) { |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
226 | PurpleXfer *xfer = PURPLE_XFER(data); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
227 | IrcXfer *xd = IRC_XFER(xfer); |
|
36028
fc5300cb3617
Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35991
diff
changeset
|
228 | int conn; |
| 8351 | 229 | |
| 230 | conn = accept(xd->fd, NULL, 0); | |
| 231 | if (conn == -1) { | |
| 232 | /* Accepting the connection failed. This could just be related | |
| 233 | * to the nonblocking nature of the listening socket, so we'll | |
| 234 | * just try again next time */ | |
| 235 | /* Let's print an error message anyway */ | |
|
21389
e1dd8142bb87
replace most calls to strerror with calls to g_strerror. strerror will return
Nathan Walp <nwalp@pidgin.im>
parents:
19859
diff
changeset
|
236 | purple_debug_warning("irc", "accept: %s\n", g_strerror(errno)); |
| 8351 | 237 | return; |
| 238 | } | |
| 239 | ||
|
32702
0446ebf22136
IRC: Use file-transfer accessor function.
Andrew Victor <andrew.victor@mxit.com>
parents:
32669
diff
changeset
|
240 | purple_input_remove(purple_xfer_get_watcher(xfer)); |
|
0446ebf22136
IRC: Use file-transfer accessor function.
Andrew Victor <andrew.victor@mxit.com>
parents:
32669
diff
changeset
|
241 | purple_xfer_set_watcher(xfer, 0); |
| 8351 | 242 | close(xd->fd); |
| 243 | xd->fd = -1; | |
| 244 | ||
|
36028
fc5300cb3617
Get rid of fair amount of copy-pasta and coverity warnings
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35991
diff
changeset
|
245 | _purple_network_set_common_socket_flags(conn); |
|
24042
098a3f96a0b9
Use non-blocking io for IRC DCC transfers.
Daniel Atallah <datallah@pidgin.im>
parents:
22591
diff
changeset
|
246 | |
| 15884 | 247 | xd->inpa = purple_input_add(conn, PURPLE_INPUT_READ, irc_dccsend_send_read, xfer); |
| 8351 | 248 | /* Start the transfer */ |
| 15884 | 249 | purple_xfer_start(xfer, conn, NULL, 0); |
| 8351 | 250 | } |
| 251 | ||
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
252 | static void |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
253 | irc_dccsend_network_listen_cb(int sock, gpointer data) |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
254 | { |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
255 | PurpleXfer *xfer = PURPLE_XFER(data); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
256 | IrcXfer *xd = IRC_XFER(xfer); |
| 15884 | 257 | PurpleConnection *gc; |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
258 | struct irc_conn *irc; |
|
37667
4523af5dc59c
irc: Port to use Gio directly for the main connection
Mike Ruprecht <cmaiku@gmail.com>
parents:
36031
diff
changeset
|
259 | GSocket *gsock; |
|
4523af5dc59c
irc: Port to use Gio directly for the main connection
Mike Ruprecht <cmaiku@gmail.com>
parents:
36031
diff
changeset
|
260 | int fd = -1; |
| 8351 | 261 | const char *arg[2]; |
| 262 | char *tmp; | |
| 263 | struct in_addr addr; | |
| 264 | unsigned short int port; | |
| 265 | ||
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
266 | /* not sure what the deal is here, but it needs to be here.. gk 20190626 */ |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
267 | xd->listen_data = NULL; |
|
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
268 | |
| 15884 | 269 | if (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL |
| 270 | || purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_REMOTE) { | |
|
34911
8b46f11b9e7e
Refactored bonjour and irc to use the GObject xfer API
Ankit Vani <a@nevitus.org>
parents:
34910
diff
changeset
|
271 | g_object_unref(xfer); |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
272 | return; |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
273 | } |
| 8351 | 274 | |
| 15884 | 275 | gc = purple_account_get_connection(purple_xfer_get_account(xfer)); |
|
32276
abc0b7c0cb86
Convert irc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32270
diff
changeset
|
276 | irc = purple_connection_get_protocol_data(gc); |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
277 | |
| 8351 | 278 | if (sock < 0) { |
| 15884 | 279 | purple_notify_error(gc, NULL, _("File Transfer Failed"), |
|
34449
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
32702
diff
changeset
|
280 | _("Unable to open a listening port."), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
32702
diff
changeset
|
281 | purple_request_cpar_from_connection(gc)); |
| 15884 | 282 | purple_xfer_cancel_local(xfer); |
| 8351 | 283 | return; |
| 284 | } | |
| 285 | ||
| 286 | xd->fd = sock; | |
| 287 | ||
| 15884 | 288 | port = purple_network_get_port_from_fd(sock); |
| 289 | purple_debug_misc("irc", "port is %hu\n", port); | |
| 8351 | 290 | /* Monitor the listening socket */ |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
291 | purple_xfer_set_watcher( |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
292 | xfer, |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
293 | purple_input_add(sock, PURPLE_INPUT_READ, irc_dccsend_send_connected, xfer) |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
294 | ); |
| 8351 | 295 | |
| 296 | /* Send the intended recipient the DCC request */ | |
|
32270
028a4b3c0402
Steps toward hiding PurpleXfer.
Daniel Atallah <datallah@pidgin.im>
parents:
32242
diff
changeset
|
297 | arg[0] = purple_xfer_get_remote_user(xfer); |
|
37667
4523af5dc59c
irc: Port to use Gio directly for the main connection
Mike Ruprecht <cmaiku@gmail.com>
parents:
36031
diff
changeset
|
298 | |
|
4523af5dc59c
irc: Port to use Gio directly for the main connection
Mike Ruprecht <cmaiku@gmail.com>
parents:
36031
diff
changeset
|
299 | /* Fetching this fd here assumes it won't be modified */ |
|
4523af5dc59c
irc: Port to use Gio directly for the main connection
Mike Ruprecht <cmaiku@gmail.com>
parents:
36031
diff
changeset
|
300 | gsock = g_socket_connection_get_socket(irc->conn); |
|
4523af5dc59c
irc: Port to use Gio directly for the main connection
Mike Ruprecht <cmaiku@gmail.com>
parents:
36031
diff
changeset
|
301 | if (gsock != NULL) { |
|
4523af5dc59c
irc: Port to use Gio directly for the main connection
Mike Ruprecht <cmaiku@gmail.com>
parents:
36031
diff
changeset
|
302 | fd = g_socket_get_fd(gsock); |
|
4523af5dc59c
irc: Port to use Gio directly for the main connection
Mike Ruprecht <cmaiku@gmail.com>
parents:
36031
diff
changeset
|
303 | } |
|
4523af5dc59c
irc: Port to use Gio directly for the main connection
Mike Ruprecht <cmaiku@gmail.com>
parents:
36031
diff
changeset
|
304 | |
|
4523af5dc59c
irc: Port to use Gio directly for the main connection
Mike Ruprecht <cmaiku@gmail.com>
parents:
36031
diff
changeset
|
305 | inet_aton(purple_network_get_my_ip(fd), &addr); |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
306 | arg[1] = tmp = g_strdup_printf( |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
307 | "\001DCC SEND \"%s\" %u %hu %" G_GOFFSET_FORMAT "\001", |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
308 | purple_xfer_get_filename(xfer), |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
309 | ntohl(addr.s_addr), |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
310 | port, |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
311 | purple_xfer_get_size(xfer) |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
312 | ); |
| 8351 | 313 | |
|
32276
abc0b7c0cb86
Convert irc prpl to use accessor functions purple_connection_get_protocol_data() and purple_connection_set_protocol_data().
Andrew Victor <andrew.victor@mxit.com>
parents:
32270
diff
changeset
|
314 | irc_cmd_privmsg(purple_connection_get_protocol_data(gc), "msg", NULL, arg); |
| 8351 | 315 | g_free(tmp); |
| 316 | } | |
| 317 | ||
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
318 | /* |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
319 | * This function is called after the user has selected a file to send. |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
320 | */ |
| 15884 | 321 | static void irc_dccsend_send_init(PurpleXfer *xfer) { |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
322 | IrcXfer *xd = IRC_XFER(xfer); |
| 15884 | 323 | PurpleConnection *gc = purple_account_get_connection(purple_xfer_get_account(xfer)); |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
324 | |
|
32270
028a4b3c0402
Steps toward hiding PurpleXfer.
Daniel Atallah <datallah@pidgin.im>
parents:
32242
diff
changeset
|
325 | purple_xfer_set_filename(xfer, g_path_get_basename(purple_xfer_get_local_filename(xfer))); |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
326 | |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
327 | /* Create a listening socket */ |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
328 | xd->listen_data = purple_network_listen_range( |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
329 | 0, |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
330 | 0, |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
331 | AF_UNSPEC, |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
332 | SOCK_STREAM, |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
333 | TRUE, |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
334 | irc_dccsend_network_listen_cb, |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
335 | xfer |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
336 | ); |
|
14329
05c3cc0c1f79
[gaim-migrate @ 16949]
Mark Doliner <markdoliner@pidgin.im>
parents:
14254
diff
changeset
|
337 | if (xd->listen_data == NULL) { |
| 15884 | 338 | purple_notify_error(gc, NULL, _("File Transfer Failed"), |
|
34449
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
32702
diff
changeset
|
339 | _("Unable to open a listening port."), |
|
bbcb198650b7
Notify API: extend purple_notify_message with PurpleRequestCommonParameters
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
32702
diff
changeset
|
340 | purple_request_cpar_from_connection(gc)); |
| 15884 | 341 | purple_xfer_cancel_local(xfer); |
|
12909
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
342 | } |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
343 | } |
|
dfcf4df1dcd7
[gaim-migrate @ 15262]
Daniel Atallah <datallah@pidgin.im>
parents:
12730
diff
changeset
|
344 | |
|
38841
518362268798
make sure all the PurpleProtocolXfer parameters are named prplxfer
Gary Kramlich <grim@reaperworld.com>
parents:
38835
diff
changeset
|
345 | PurpleXfer *irc_dccsend_new_xfer(PurpleProtocolXfer *prplxfer, PurpleConnection *gc, const char *who) { |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
346 | return g_object_new( |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
347 | IRC_TYPE_XFER, |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
348 | "account", purple_connection_get_account(gc), |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
349 | "type", PURPLE_XFER_TYPE_SEND, |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
350 | "remote-user", who, |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
351 | NULL |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
352 | ); |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
353 | } |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
354 | |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
355 | /** |
| 15884 | 356 | * Purple calls this function when the user selects Send File from the |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
357 | * buddy menu |
| 15884 | 358 | * It sets up the PurpleXfer struct and tells Purple to go ahead |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
359 | */ |
|
38841
518362268798
make sure all the PurpleProtocolXfer parameters are named prplxfer
Gary Kramlich <grim@reaperworld.com>
parents:
38835
diff
changeset
|
360 | void irc_dccsend_send_file(PurpleProtocolXfer *prplxfer, PurpleConnection *gc, const char *who, const char *file) { |
|
518362268798
make sure all the PurpleProtocolXfer parameters are named prplxfer
Gary Kramlich <grim@reaperworld.com>
parents:
38835
diff
changeset
|
361 | PurpleXfer *xfer = irc_dccsend_new_xfer(prplxfer, gc, who); |
|
12143
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
362 | |
|
09f216663302
[gaim-migrate @ 14444]
Evan Schoenberg <evands@pidgin.im>
parents:
11656
diff
changeset
|
363 | /* Perform the request */ |
|
9466
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
8838
diff
changeset
|
364 | if (file) |
| 15884 | 365 | purple_xfer_request_accepted(xfer, file); |
|
9466
b6425eab60ca
[gaim-migrate @ 10291]
Daniel Atallah <datallah@pidgin.im>
parents:
8838
diff
changeset
|
366 | else |
| 15884 | 367 | purple_xfer_request(xfer); |
| 8351 | 368 | } |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
369 | |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
370 | /****************************************************************************** |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
371 | * PurpleXfer Implementation |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
372 | *****************************************************************************/ |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
373 | static void |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
374 | irc_dccsend_init(PurpleXfer *xfer) { |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
375 | PurpleXferType type = purple_xfer_get_xfer_type(xfer); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
376 | |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
377 | if(type == PURPLE_XFER_TYPE_SEND) { |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
378 | irc_dccsend_send_init(xfer); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
379 | } else if(type == PURPLE_XFER_TYPE_RECEIVE) { |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
380 | irc_dccsend_recv_init(xfer); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
381 | } |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
382 | } |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
383 | |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
384 | /****************************************************************************** |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
385 | * GObject Implementation |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
386 | *****************************************************************************/ |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
387 | static void |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
388 | irc_xfer_init(IrcXfer *xfer) { |
|
39670
8d95b195ce69
Cleanups from review
Gary Kramlich <grim@reaperworld.com>
parents:
39669
diff
changeset
|
389 | xfer->fd = -1; |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
390 | } |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
391 | |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
392 | static void |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
393 | irc_xfer_finalize(GObject *obj) { |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
394 | IrcXfer *xfer = IRC_XFER(obj); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
395 | |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
396 | /* clean up the receiving proprties */ |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
397 | g_free(xfer->ip); |
|
39670
8d95b195ce69
Cleanups from review
Gary Kramlich <grim@reaperworld.com>
parents:
39669
diff
changeset
|
398 | g_free(xfer->rxqueue); |
|
39669
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
399 | |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
400 | /* clean up the sending properties */ |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
401 | g_clear_pointer(&xfer->listen_data, purple_network_listen_cancel); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
402 | if(xfer->inpa > 0) { |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
403 | purple_input_remove(xfer->inpa); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
404 | } |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
405 | if(xfer->fd != -1) { |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
406 | close(xfer->fd); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
407 | } |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
408 | |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
409 | G_OBJECT_CLASS(irc_xfer_parent_class)->finalize(obj); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
410 | } |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
411 | |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
412 | static void |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
413 | irc_xfer_class_finalize(IrcXferClass *klass) { |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
414 | |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
415 | } |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
416 | |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
417 | static void |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
418 | irc_xfer_class_init(IrcXferClass *klass) { |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
419 | GObjectClass *obj_class = G_OBJECT_CLASS(klass); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
420 | PurpleXferClass *xfer_class = PURPLE_XFER_CLASS(klass); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
421 | |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
422 | obj_class->finalize = irc_xfer_finalize; |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
423 | |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
424 | xfer_class->init = irc_dccsend_init; |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
425 | xfer_class->ack = irc_dccsend_recv_ack; |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
426 | xfer_class->write = irc_dccsend_send_write; |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
427 | } |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
428 | |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
429 | void |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
430 | irc_xfer_register(GTypeModule *module) { |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
431 | irc_xfer_register_type(module); |
|
bab07ecb9330
Make PurpleXfer a derivable type and create subclasses in all the protocols that support file transfers
Gary Kramlich <grim@reaperworld.com>
parents:
38841
diff
changeset
|
432 | } |