Mercurial > pidgin
comparison src/protocols/msn/slpmsg.c @ 9193:502707ca1836
[gaim-migrate @ 9988]
Patch by Felipe Contreras to add MSN file transfer and buddy icons. Please
test and report any bugs!
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sun, 06 Jun 2004 02:39:08 +0000 |
parents | |
children | ab6636c5a136 |
comparison
equal
deleted
inserted
replaced
9192:5655dcd94d0f | 9193:502707ca1836 |
---|---|
1 /** | |
2 * @file slpmsg.h SLP Message functions | |
3 * | |
4 * gaim | |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
19 */ | |
20 #include "msn.h" | |
21 #include "slpmsg.h" | |
22 #include "slplink.h" | |
23 | |
24 /************************************************************************** | |
25 * SLP Message | |
26 **************************************************************************/ | |
27 | |
28 MsnSlpMessage * | |
29 msn_slpmsg_new(MsnSlpLink *slplink) | |
30 { | |
31 MsnSlpMessage *slpmsg; | |
32 slpmsg = g_new0(MsnSlpMessage, 1); | |
33 | |
34 slpmsg->slplink = slplink; | |
35 | |
36 slplink->slp_msgs = | |
37 g_list_append(slplink->slp_msgs, slpmsg); | |
38 | |
39 return slpmsg; | |
40 } | |
41 | |
42 void | |
43 msn_slpmsg_destroy(MsnSlpMessage *slpmsg) | |
44 { | |
45 MsnSlpLink *slplink; | |
46 | |
47 slplink = slpmsg->slplink; | |
48 | |
49 if (slpmsg->fp != NULL) | |
50 fclose(slpmsg->fp); | |
51 | |
52 if (slpmsg->buffer != NULL) | |
53 g_free(slpmsg->buffer); | |
54 | |
55 #ifdef DEBUG_SLP | |
56 /* | |
57 if (slpmsg->info != NULL) | |
58 g_free(slpmsg->info); | |
59 */ | |
60 #endif | |
61 | |
62 if (slpmsg->msg != NULL) | |
63 { | |
64 if (slpmsg->msg->trans != NULL) | |
65 { | |
66 slpmsg->msg->trans->callbacks = NULL; | |
67 slpmsg->msg->trans->data = NULL; | |
68 } | |
69 } | |
70 | |
71 slplink->slp_msgs = | |
72 g_list_remove(slplink->slp_msgs, slpmsg); | |
73 | |
74 g_free(slpmsg); | |
75 } | |
76 | |
77 void | |
78 msn_slpmsg_set_body(MsnSlpMessage *slpmsg, const char *body, | |
79 long long size) | |
80 { | |
81 if (body != NULL) | |
82 slpmsg->buffer = g_memdup(body, size); | |
83 else | |
84 slpmsg->buffer = g_new0(char, size); | |
85 | |
86 slpmsg->size = size; | |
87 } | |
88 | |
89 void | |
90 msn_slpmsg_open_file(MsnSlpMessage *slpmsg, const char *file_name) | |
91 { | |
92 struct stat st; | |
93 | |
94 slpmsg->fp = fopen(file_name, "r"); | |
95 | |
96 if (stat(file_name, &st) == 0) | |
97 slpmsg->size = st.st_size; | |
98 } | |
99 | |
100 #ifdef DEBUG_SLP | |
101 const void | |
102 msn_slpmsg_show(MsnMessage *msg) | |
103 { | |
104 const char *info; | |
105 gboolean text; | |
106 guint32 flags; | |
107 | |
108 text = FALSE; | |
109 | |
110 flags = GUINT32_TO_LE(msg->msnslp_header.flags);; | |
111 | |
112 switch (flags) | |
113 { | |
114 case 0x0: | |
115 info = "SLP CONTROL"; | |
116 text = TRUE; | |
117 break; | |
118 case 0x2: | |
119 info = "SLP ACK"; break; | |
120 case 0x20: | |
121 info = "SLP DATA"; break; | |
122 default: | |
123 info = "SLP UNKNOWN"; break; | |
124 } | |
125 | |
126 msn_message_show_readable(msg, info, text); | |
127 } | |
128 #endif | |
129 | |
130 MsnSlpMessage * | |
131 msn_slpmsg_sip_new(MsnSlpCall *slpcall, int cseq, | |
132 const char *header, const char *branch, | |
133 const char *content_type, const char *content) | |
134 { | |
135 MsnSlpLink *slplink; | |
136 MsnSlpMessage *slpmsg; | |
137 char *body; | |
138 gsize body_len; | |
139 gsize content_len; | |
140 | |
141 g_return_val_if_fail(slpcall != NULL, NULL); | |
142 g_return_val_if_fail(header != NULL, NULL); | |
143 | |
144 slplink = slpcall->slplink; | |
145 | |
146 /* Let's remember that "content" should end with a 0x00 */ | |
147 | |
148 content_len = (content != NULL) ? strlen(content) + 1 : 0; | |
149 | |
150 body = g_strdup_printf( | |
151 "%s\r\n" | |
152 "To: <msnmsgr:%s>\r\n" | |
153 "From: <msnmsgr:%s>\r\n" | |
154 "Via: MSNSLP/1.0/TLP ;branch={%s}\r\n" | |
155 "CSeq: %d\r\n" | |
156 "Call-ID: {%s}\r\n" | |
157 "Max-Forwards: 0\r\n" | |
158 "Content-Type: %s\r\n" | |
159 "Content-Length: %d\r\n" | |
160 "\r\n", | |
161 header, | |
162 slplink->remote_user, | |
163 slplink->local_user, | |
164 branch, | |
165 cseq, | |
166 slpcall->id, | |
167 content_type, | |
168 content_len); | |
169 | |
170 body_len = strlen(body); | |
171 | |
172 if (content_len > 0) | |
173 { | |
174 body_len += content_len; | |
175 body = g_realloc(body, body_len); | |
176 g_strlcat(body, content, body_len); | |
177 } | |
178 | |
179 slpmsg = msn_slpmsg_new(slplink); | |
180 msn_slpmsg_set_body(slpmsg, body, body_len); | |
181 | |
182 slpmsg->sip = TRUE; | |
183 | |
184 g_free(body); | |
185 | |
186 return slpmsg; | |
187 } |