Mercurial > pidgin
annotate src/protocols/msn/slpmsg.c @ 10296:a7b2fd5efcf2
[gaim-migrate @ 11476]
Some "random updates" updates from patch 1077274 by Felipe Contreras:
"Some changes in the behaviour of slpcalls (for FT),
free some unused structures and properly close
switchboard connections."
Looks good to me, and seems to have fixed a mysterious FT problem that I had
been pretending didn't exist.
committer: Tailor Script <tailor@pidgin.im>
| author | Stu Tomlinson <stu@nosnilmot.com> |
|---|---|
| date | Thu, 02 Dec 2004 16:07:26 +0000 |
| parents | f776e117c17b |
| children | 56cc5d49472b |
| rev | line source |
|---|---|
| 9193 | 1 /** |
| 2 * @file slpmsg.h SLP Message functions | |
| 3 * | |
| 4 * gaim | |
| 5 * | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
6 * Gaim is the legal property of its developers, whose names are too numerous |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
8 * source distribution. |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
9 * |
| 9193 | 10 * This program is free software; you can redistribute it and/or modify |
| 11 * it under the terms of the GNU General Public License as published by | |
| 12 * the Free Software Foundation; either version 2 of the License, or | |
| 13 * (at your option) any later version. | |
| 14 * | |
| 15 * This program is distributed in the hope that it will be useful, | |
| 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 * GNU General Public License for more details. | |
| 19 * | |
| 20 * You should have received a copy of the GNU General Public License | |
| 21 * along with this program; if not, write to the Free Software | |
| 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 23 */ | |
| 24 #include "msn.h" | |
| 25 #include "slpmsg.h" | |
| 26 #include "slplink.h" | |
| 27 | |
| 28 /************************************************************************** | |
| 29 * SLP Message | |
| 30 **************************************************************************/ | |
| 31 | |
| 32 MsnSlpMessage * | |
| 33 msn_slpmsg_new(MsnSlpLink *slplink) | |
| 34 { | |
| 35 MsnSlpMessage *slpmsg; | |
| 36 slpmsg = g_new0(MsnSlpMessage, 1); | |
| 37 | |
| 38 slpmsg->slplink = slplink; | |
| 39 | |
| 40 slplink->slp_msgs = | |
| 41 g_list_append(slplink->slp_msgs, slpmsg); | |
| 42 | |
| 43 return slpmsg; | |
| 44 } | |
| 45 | |
| 46 void | |
| 47 msn_slpmsg_destroy(MsnSlpMessage *slpmsg) | |
| 48 { | |
| 49 MsnSlpLink *slplink; | |
| 50 | |
| 51 slplink = slpmsg->slplink; | |
| 52 | |
| 53 if (slpmsg->fp != NULL) | |
| 54 fclose(slpmsg->fp); | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
55 |
| 9193 | 56 if (slpmsg->buffer != NULL) |
| 57 g_free(slpmsg->buffer); | |
| 58 | |
| 59 #ifdef DEBUG_SLP | |
| 60 /* | |
| 61 if (slpmsg->info != NULL) | |
| 62 g_free(slpmsg->info); | |
| 63 */ | |
| 64 #endif | |
| 65 | |
| 66 if (slpmsg->msg != NULL) | |
| 67 { | |
| 10284 | 68 MsnTransaction *trans; |
| 69 | |
| 70 trans = slpmsg->msg->trans; | |
| 71 | |
| 72 if (trans != NULL) | |
| 9193 | 73 { |
| 10284 | 74 /* Something is pointing to this slpmsg, so we should remove that |
| 75 * pointer to prevent a crash. */ | |
| 76 | |
| 77 if (trans->callbacks != NULL && trans->has_custom_callbacks) | |
| 78 g_hash_table_destroy(trans->callbacks); | |
| 79 | |
| 80 trans->callbacks = NULL; | |
| 81 trans->data = NULL; | |
| 9193 | 82 } |
| 83 } | |
| 84 | |
| 85 slplink->slp_msgs = | |
| 86 g_list_remove(slplink->slp_msgs, slpmsg); | |
| 87 | |
| 88 g_free(slpmsg); | |
| 89 } | |
| 90 | |
| 91 void | |
| 92 msn_slpmsg_set_body(MsnSlpMessage *slpmsg, const char *body, | |
| 93 long long size) | |
| 94 { | |
| 95 if (body != NULL) | |
| 96 slpmsg->buffer = g_memdup(body, size); | |
| 97 else | |
| 98 slpmsg->buffer = g_new0(char, size); | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
99 |
| 9193 | 100 slpmsg->size = size; |
| 101 } | |
| 102 | |
| 103 void | |
| 104 msn_slpmsg_open_file(MsnSlpMessage *slpmsg, const char *file_name) | |
| 105 { | |
| 106 struct stat st; | |
| 107 | |
| 9219 | 108 slpmsg->fp = fopen(file_name, "rb"); |
| 9193 | 109 |
| 110 if (stat(file_name, &st) == 0) | |
| 111 slpmsg->size = st.st_size; | |
| 112 } | |
| 113 | |
| 114 #ifdef DEBUG_SLP | |
| 115 const void | |
| 116 msn_slpmsg_show(MsnMessage *msg) | |
| 117 { | |
| 118 const char *info; | |
| 119 gboolean text; | |
| 120 guint32 flags; | |
| 121 | |
| 122 text = FALSE; | |
| 123 | |
| 9775 | 124 flags = GUINT32_TO_LE(msg->msnslp_header.flags); |
| 9193 | 125 |
| 126 switch (flags) | |
| 127 { | |
| 128 case 0x0: | |
| 129 info = "SLP CONTROL"; | |
| 130 text = TRUE; | |
| 131 break; | |
| 132 case 0x2: | |
| 133 info = "SLP ACK"; break; | |
| 134 case 0x20: | |
| 10225 | 135 case 0x1000030: |
| 9193 | 136 info = "SLP DATA"; break; |
| 137 default: | |
| 138 info = "SLP UNKNOWN"; break; | |
| 139 } | |
| 140 | |
| 141 msn_message_show_readable(msg, info, text); | |
| 142 } | |
| 143 #endif | |
| 144 | |
| 145 MsnSlpMessage * | |
| 146 msn_slpmsg_sip_new(MsnSlpCall *slpcall, int cseq, | |
| 147 const char *header, const char *branch, | |
| 148 const char *content_type, const char *content) | |
| 149 { | |
| 150 MsnSlpLink *slplink; | |
| 151 MsnSlpMessage *slpmsg; | |
| 152 char *body; | |
| 153 gsize body_len; | |
| 154 gsize content_len; | |
| 155 | |
| 156 g_return_val_if_fail(slpcall != NULL, NULL); | |
| 157 g_return_val_if_fail(header != NULL, NULL); | |
| 158 | |
| 159 slplink = slpcall->slplink; | |
| 160 | |
| 161 /* Let's remember that "content" should end with a 0x00 */ | |
| 162 | |
| 163 content_len = (content != NULL) ? strlen(content) + 1 : 0; | |
| 164 | |
| 165 body = g_strdup_printf( | |
| 166 "%s\r\n" | |
| 167 "To: <msnmsgr:%s>\r\n" | |
| 168 "From: <msnmsgr:%s>\r\n" | |
| 169 "Via: MSNSLP/1.0/TLP ;branch={%s}\r\n" | |
| 170 "CSeq: %d\r\n" | |
| 171 "Call-ID: {%s}\r\n" | |
| 172 "Max-Forwards: 0\r\n" | |
| 173 "Content-Type: %s\r\n" | |
| 10112 | 174 "Content-Length: %" G_GSIZE_FORMAT "\r\n" |
| 9193 | 175 "\r\n", |
| 176 header, | |
| 177 slplink->remote_user, | |
| 178 slplink->local_user, | |
| 179 branch, | |
| 180 cseq, | |
| 181 slpcall->id, | |
| 182 content_type, | |
| 183 content_len); | |
| 184 | |
| 185 body_len = strlen(body); | |
| 186 | |
| 187 if (content_len > 0) | |
| 188 { | |
| 189 body_len += content_len; | |
| 190 body = g_realloc(body, body_len); | |
| 191 g_strlcat(body, content, body_len); | |
| 192 } | |
| 193 | |
| 194 slpmsg = msn_slpmsg_new(slplink); | |
| 195 msn_slpmsg_set_body(slpmsg, body, body_len); | |
| 196 | |
| 197 slpmsg->sip = TRUE; | |
| 198 | |
| 199 g_free(body); | |
| 200 | |
| 201 return slpmsg; | |
| 202 } |
