annotate libpurple/protocols/msn/xfer.c @ 30934:4e097dfb7784

Fix some leaks. Header and footer are allocated, copied and not freed.
author Elliott Sales de Andrade <qulogic@pidgin.im>
date Sun, 21 Nov 2010 08:47:08 +0000
parents eabeba9c823f
children 72e6fa6caecc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30832
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
1 #include "internal.h"
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
2 #include "debug.h"
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
3
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
4 #include "sbconn.h"
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
5 #include "xfer.h"
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
6
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
7 /**************************************************************************
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
8 * Xfer
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
9 **************************************************************************/
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
10
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
11 void
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
12 msn_xfer_init(PurpleXfer *xfer)
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
13 {
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
14 MsnSlpCall *slpcall;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
15 /* MsnSlpLink *slplink; */
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
16 char *content;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
17
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
18 purple_debug_info("msn", "xfer_init\n");
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
19
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
20 slpcall = xfer->data;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
21
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
22 /* Send Ok */
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
23 content = g_strdup_printf("SessionID: %lu\r\n\r\n",
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
24 slpcall->session_id);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
25
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
26 msn_slp_send_ok(slpcall, slpcall->branch, "application/x-msnmsgr-sessionreqbody",
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
27 content);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
28
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
29 g_free(content);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
30 msn_slplink_send_queued_slpmsgs(slpcall->slplink);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
31 }
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
32
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
33 void
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
34 msn_xfer_cancel(PurpleXfer *xfer)
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
35 {
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
36 MsnSlpCall *slpcall;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
37 char *content;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
38
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
39 g_return_if_fail(xfer != NULL);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
40 g_return_if_fail(xfer->data != NULL);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
41
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
42 slpcall = xfer->data;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
43
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
44 if (purple_xfer_get_status(xfer) == PURPLE_XFER_STATUS_CANCEL_LOCAL)
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
45 {
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
46 if (slpcall->started)
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
47 {
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
48 msn_slpcall_close(slpcall);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
49 }
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
50 else
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
51 {
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
52 content = g_strdup_printf("SessionID: %lu\r\n\r\n",
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
53 slpcall->session_id);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
54
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
55 msn_slp_send_decline(slpcall, slpcall->branch, "application/x-msnmsgr-sessionreqbody",
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
56 content);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
57
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
58 g_free(content);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
59 msn_slplink_send_queued_slpmsgs(slpcall->slplink);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
60
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
61 if (purple_xfer_get_type(xfer) == PURPLE_XFER_SEND)
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
62 slpcall->wasted = TRUE;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
63 else
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
64 msn_slpcall_destroy(slpcall);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
65 }
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
66 }
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
67 }
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
68
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
69 gssize
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
70 msn_xfer_write(const guchar *data, gsize len, PurpleXfer *xfer)
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
71 {
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
72 MsnSlpCall *slpcall;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
73
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
74 g_return_val_if_fail(xfer != NULL, -1);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
75 g_return_val_if_fail(data != NULL, -1);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
76 g_return_val_if_fail(len > 0, -1);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
77
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
78 g_return_val_if_fail(purple_xfer_get_type(xfer) == PURPLE_XFER_SEND, -1);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
79
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
80 slpcall = xfer->data;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
81 /* Not sure I trust it'll be there */
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
82 g_return_val_if_fail(slpcall != NULL, -1);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
83
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
84 g_return_val_if_fail(slpcall->xfer_msg != NULL, -1);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
85
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
86 slpcall->u.outgoing.len = len;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
87 slpcall->u.outgoing.data = data;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
88 msn_slplink_send_msgpart(slpcall->slplink, slpcall->xfer_msg);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
89
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
90 return MIN(MSN_SBCONN_MAX_SIZE, len);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
91 }
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
92
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
93 gssize
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
94 msn_xfer_read(guchar **data, PurpleXfer *xfer)
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
95 {
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
96 MsnSlpCall *slpcall;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
97 gsize len;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
98
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
99 g_return_val_if_fail(xfer != NULL, -1);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
100 g_return_val_if_fail(data != NULL, -1);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
101
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
102 g_return_val_if_fail(purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE, -1);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
103
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
104 slpcall = xfer->data;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
105 /* Not sure I trust it'll be there */
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
106 g_return_val_if_fail(slpcall != NULL, -1);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
107
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
108 /* Just pass up the whole GByteArray. We'll make another. */
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
109 *data = slpcall->u.incoming_data->data;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
110 len = slpcall->u.incoming_data->len;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
111
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
112 g_byte_array_free(slpcall->u.incoming_data, FALSE);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
113 slpcall->u.incoming_data = g_byte_array_new();
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
114
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
115 return len;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
116 }
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
117
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
118 void
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
119 msn_xfer_end_cb(MsnSlpCall *slpcall, MsnSession *session)
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
120 {
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
121 if ((purple_xfer_get_status(slpcall->xfer) != PURPLE_XFER_STATUS_DONE) &&
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
122 (purple_xfer_get_status(slpcall->xfer) != PURPLE_XFER_STATUS_CANCEL_REMOTE) &&
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
123 (purple_xfer_get_status(slpcall->xfer) != PURPLE_XFER_STATUS_CANCEL_LOCAL))
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
124 {
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
125 purple_xfer_cancel_remote(slpcall->xfer);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
126 }
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
127 }
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
128
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
129 void
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
130 msn_xfer_completed_cb(MsnSlpCall *slpcall, const guchar *body,
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
131 gsize size)
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
132 {
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
133 PurpleXfer *xfer = slpcall->xfer;
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
134
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
135 purple_xfer_set_completed(xfer, TRUE);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
136 purple_xfer_end(xfer);
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
137 }
eabeba9c823f Move msn_xfer code to it's own module aiming to simplify slp code.
masca@cpw.pidgin.im
parents:
diff changeset
138