Mercurial > pidgin
annotate src/protocols/msn/slpmsg.c @ 10225:ecf3ce2e2ab1
[gaim-migrate @ 11357]
This is mostly a patch from Felipe Contreras that eliminates MSN switchboard
errors and fixes MSN buddy icon syncronization, with some tweaks by me.
Thank Felipe if it works, blame me if something broke.
I also fixed a couple of text markup escaping things, fixed a glib warning that
was bugging me, fix a rare SILC crash, and make gtkstatusselector.c compile
(but do nothing) with gtk < 2.4
committer: Tailor Script <tailor@pidgin.im>
| author | Stu Tomlinson <stu@nosnilmot.com> |
|---|---|
| date | Sun, 21 Nov 2004 17:48:09 +0000 |
| parents | 1a91e814e9d8 |
| children | f776e117c17b |
| 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 { | |
| 68 if (slpmsg->msg->trans != NULL) | |
| 69 { | |
| 70 slpmsg->msg->trans->callbacks = NULL; | |
| 71 slpmsg->msg->trans->data = NULL; | |
| 72 } | |
| 73 } | |
| 74 | |
| 75 slplink->slp_msgs = | |
| 76 g_list_remove(slplink->slp_msgs, slpmsg); | |
| 77 | |
| 78 g_free(slpmsg); | |
| 79 } | |
| 80 | |
| 81 void | |
| 82 msn_slpmsg_set_body(MsnSlpMessage *slpmsg, const char *body, | |
| 83 long long size) | |
| 84 { | |
| 85 if (body != NULL) | |
| 86 slpmsg->buffer = g_memdup(body, size); | |
| 87 else | |
| 88 slpmsg->buffer = g_new0(char, size); | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
89 |
| 9193 | 90 slpmsg->size = size; |
| 91 } | |
| 92 | |
| 93 void | |
| 94 msn_slpmsg_open_file(MsnSlpMessage *slpmsg, const char *file_name) | |
| 95 { | |
| 96 struct stat st; | |
| 97 | |
| 9219 | 98 slpmsg->fp = fopen(file_name, "rb"); |
| 9193 | 99 |
| 100 if (stat(file_name, &st) == 0) | |
| 101 slpmsg->size = st.st_size; | |
| 102 } | |
| 103 | |
| 104 #ifdef DEBUG_SLP | |
| 105 const void | |
| 106 msn_slpmsg_show(MsnMessage *msg) | |
| 107 { | |
| 108 const char *info; | |
| 109 gboolean text; | |
| 110 guint32 flags; | |
| 111 | |
| 112 text = FALSE; | |
| 113 | |
| 9775 | 114 flags = GUINT32_TO_LE(msg->msnslp_header.flags); |
| 9193 | 115 |
| 116 switch (flags) | |
| 117 { | |
| 118 case 0x0: | |
| 119 info = "SLP CONTROL"; | |
| 120 text = TRUE; | |
| 121 break; | |
| 122 case 0x2: | |
| 123 info = "SLP ACK"; break; | |
| 124 case 0x20: | |
| 10225 | 125 case 0x1000030: |
| 9193 | 126 info = "SLP DATA"; break; |
| 127 default: | |
| 128 info = "SLP UNKNOWN"; break; | |
| 129 } | |
| 130 | |
| 131 msn_message_show_readable(msg, info, text); | |
| 132 } | |
| 133 #endif | |
| 134 | |
| 135 MsnSlpMessage * | |
| 136 msn_slpmsg_sip_new(MsnSlpCall *slpcall, int cseq, | |
| 137 const char *header, const char *branch, | |
| 138 const char *content_type, const char *content) | |
| 139 { | |
| 140 MsnSlpLink *slplink; | |
| 141 MsnSlpMessage *slpmsg; | |
| 142 char *body; | |
| 143 gsize body_len; | |
| 144 gsize content_len; | |
| 145 | |
| 146 g_return_val_if_fail(slpcall != NULL, NULL); | |
| 147 g_return_val_if_fail(header != NULL, NULL); | |
| 148 | |
| 149 slplink = slpcall->slplink; | |
| 150 | |
| 151 /* Let's remember that "content" should end with a 0x00 */ | |
| 152 | |
| 153 content_len = (content != NULL) ? strlen(content) + 1 : 0; | |
| 154 | |
| 155 body = g_strdup_printf( | |
| 156 "%s\r\n" | |
| 157 "To: <msnmsgr:%s>\r\n" | |
| 158 "From: <msnmsgr:%s>\r\n" | |
| 159 "Via: MSNSLP/1.0/TLP ;branch={%s}\r\n" | |
| 160 "CSeq: %d\r\n" | |
| 161 "Call-ID: {%s}\r\n" | |
| 162 "Max-Forwards: 0\r\n" | |
| 163 "Content-Type: %s\r\n" | |
| 10112 | 164 "Content-Length: %" G_GSIZE_FORMAT "\r\n" |
| 9193 | 165 "\r\n", |
| 166 header, | |
| 167 slplink->remote_user, | |
| 168 slplink->local_user, | |
| 169 branch, | |
| 170 cseq, | |
| 171 slpcall->id, | |
| 172 content_type, | |
| 173 content_len); | |
| 174 | |
| 175 body_len = strlen(body); | |
| 176 | |
| 177 if (content_len > 0) | |
| 178 { | |
| 179 body_len += content_len; | |
| 180 body = g_realloc(body, body_len); | |
| 181 g_strlcat(body, content, body_len); | |
| 182 } | |
| 183 | |
| 184 slpmsg = msn_slpmsg_new(slplink); | |
| 185 msn_slpmsg_set_body(slpmsg, body, body_len); | |
| 186 | |
| 187 slpmsg->sip = TRUE; | |
| 188 | |
| 189 g_free(body); | |
| 190 | |
| 191 return slpmsg; | |
| 192 } |
