Mercurial > pidgin
annotate src/protocols/msn/slpcall.c @ 10481:bcfea6c3d5c9
[gaim-migrate @ 11769]
Patch 1093958 from Felipe Contreras. It fixes stuff.
I also made some tweaks to make valgrind a bit happier.
committer: Tailor Script <tailor@pidgin.im>
| author | Stu Tomlinson <stu@nosnilmot.com> |
|---|---|
| date | Fri, 07 Jan 2005 02:48:33 +0000 |
| parents | 92d4a25fd33c |
| children | 1a97d5e88d12 |
| rev | line source |
|---|---|
| 9193 | 1 /** |
| 2 * @file slpcall.c SLP Call 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 "slpcall.h" | |
| 26 #include "slpsession.h" | |
| 27 | |
| 28 #include "slp.h" | |
| 29 | |
| 30 /************************************************************************** | |
| 31 * Util | |
| 32 **************************************************************************/ | |
| 33 | |
| 34 char * | |
| 35 rand_guid() | |
| 36 { | |
| 37 return g_strdup_printf("%4X%4X-%4X-%4X-%4X-%4X%4X%4X", | |
| 38 rand() % 0xAAFF + 0x1111, | |
| 39 rand() % 0xAAFF + 0x1111, | |
| 40 rand() % 0xAAFF + 0x1111, | |
| 41 rand() % 0xAAFF + 0x1111, | |
| 42 rand() % 0xAAFF + 0x1111, | |
| 43 rand() % 0xAAFF + 0x1111, | |
| 44 rand() % 0xAAFF + 0x1111, | |
| 45 rand() % 0xAAFF + 0x1111); | |
| 46 } | |
| 47 | |
| 48 /************************************************************************** | |
| 49 * SLP Call | |
| 50 **************************************************************************/ | |
| 51 | |
| 52 MsnSlpCall * | |
| 53 msn_slp_call_new(MsnSlpLink *slplink) | |
| 54 { | |
| 55 MsnSlpCall *slpcall; | |
| 56 | |
| 57 g_return_val_if_fail(slplink != NULL, NULL); | |
| 58 | |
| 59 slpcall = g_new0(MsnSlpCall, 1); | |
| 60 | |
| 61 slpcall->slplink = slplink; | |
| 62 slplink->slp_calls = | |
| 63 g_list_append(slplink->slp_calls, slpcall); | |
| 64 | |
| 10225 | 65 slpcall->timer = gaim_timeout_add(MSN_SLPCALL_TIMEOUT, msn_slp_call_timeout, slpcall); |
| 66 | |
| 9193 | 67 return slpcall; |
| 68 } | |
| 69 | |
| 70 void | |
| 71 msn_slp_call_destroy(MsnSlpCall *slpcall) | |
| 72 { | |
| 73 GList *e; | |
| 74 | |
| 75 g_return_if_fail(slpcall != NULL); | |
| 76 | |
| 10225 | 77 if (slpcall->timer) |
| 78 gaim_timeout_remove(slpcall->timer); | |
| 79 | |
| 9193 | 80 if (slpcall->id != NULL) |
| 81 g_free(slpcall->id); | |
| 82 | |
| 83 if (slpcall->branch != NULL) | |
| 84 g_free(slpcall->branch); | |
| 85 | |
| 86 if (slpcall->data_info != NULL) | |
| 87 g_free(slpcall->data_info); | |
| 88 | |
| 89 slpcall->slplink->slp_calls = | |
| 90 g_list_remove(slpcall->slplink->slp_calls, slpcall); | |
| 91 | |
| 92 for (e = slpcall->slplink->slp_msgs; e != NULL; ) | |
| 93 { | |
| 94 MsnSlpMessage *slpmsg = e->data; | |
| 95 e = e->next; | |
| 96 | |
| 97 g_return_if_fail(slpmsg != NULL); | |
| 98 | |
| 10481 | 99 #if 0 |
| 10451 | 100 gaim_debug_info("msn", "slpcall destroy: trying slp_msg (%p)\n", |
| 10345 | 101 slpmsg); |
| 10481 | 102 #endif |
| 10345 | 103 |
| 9193 | 104 if (slpmsg->slpcall == slpcall) |
| 10481 | 105 { |
| 9193 | 106 msn_slpmsg_destroy(slpmsg); |
| 10481 | 107 } |
| 9193 | 108 } |
| 109 | |
|
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
110 if (slpcall->end_cb != NULL) |
|
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
111 slpcall->end_cb(slpcall); |
| 9193 | 112 |
| 113 g_free(slpcall); | |
| 114 } | |
| 115 | |
| 116 void | |
| 10345 | 117 msn_slp_call_init(MsnSlpCall *slpcall, MsnSlpCallType type) |
| 118 { | |
| 119 slpcall->session_id = rand() % 0xFFFFFF00 + 4; | |
| 120 slpcall->id = rand_guid(); | |
| 121 slpcall->type = type; | |
| 122 } | |
| 123 | |
| 124 void | |
| 125 msn_slp_call_session_init(MsnSlpCall *slpcall) | |
| 126 { | |
| 127 MsnSlpSession *slpsession; | |
| 128 | |
| 129 slpsession = msn_slp_session_new(slpcall); | |
| 130 | |
| 131 if (slpcall->session_init_cb) | |
| 132 slpcall->session_init_cb(slpsession); | |
| 133 | |
| 134 slpcall->started = TRUE; | |
| 135 } | |
| 136 | |
| 137 void | |
| 9193 | 138 msn_slp_call_invite(MsnSlpCall *slpcall, const char *euf_guid, |
| 139 int app_id, const char *context) | |
| 140 { | |
| 141 MsnSlpLink *slplink; | |
| 142 MsnSlpMessage *slpmsg; | |
| 143 char *header; | |
| 144 char *content; | |
| 145 | |
| 146 g_return_if_fail(slpcall != NULL); | |
| 147 g_return_if_fail(context != NULL); | |
| 148 | |
| 149 slplink = slpcall->slplink; | |
| 150 | |
| 10000 | 151 slpcall->branch = rand_guid(); |
| 9193 | 152 |
| 153 content = g_strdup_printf( | |
| 154 "EUF-GUID: {%s}\r\n" | |
| 155 "SessionID: %lu\r\n" | |
| 156 "AppID: %d\r\n" | |
| 157 "Context: %s\r\n\r\n", | |
| 158 euf_guid, | |
| 159 slpcall->session_id, | |
| 160 app_id, | |
| 161 context); | |
| 162 | |
| 163 header = g_strdup_printf("INVITE MSNMSGR:%s MSNSLP/1.0", | |
| 164 slplink->remote_user); | |
| 165 | |
| 10000 | 166 slpmsg = msn_slpmsg_sip_new(slpcall, 0, header, slpcall->branch, |
| 9193 | 167 "application/x-msnmsgr-sessionreqbody", content); |
| 10345 | 168 #ifdef MSN_DEBUG_SLP |
| 9193 | 169 slpmsg->info = "SLP INVITE"; |
| 170 slpmsg->text_body = TRUE; | |
| 171 #endif | |
| 172 | |
| 173 msn_slplink_send_slpmsg(slplink, slpmsg); | |
| 174 | |
| 175 g_free(header); | |
| 176 g_free(content); | |
| 177 } | |
| 178 | |
| 179 void | |
| 180 msn_slp_call_close(MsnSlpCall *slpcall) | |
| 181 { | |
| 182 g_return_if_fail(slpcall != NULL); | |
| 183 g_return_if_fail(slpcall->slplink != NULL); | |
| 184 | |
| 185 send_bye(slpcall, "application/x-msnmsgr-sessionclosebody"); | |
| 186 msn_slplink_unleash(slpcall->slplink); | |
| 187 msn_slp_call_destroy(slpcall); | |
| 188 } | |
| 189 | |
| 10225 | 190 gboolean |
| 191 msn_slp_call_timeout(gpointer data) | |
| 192 { | |
| 10296 | 193 MsnSlpCall *slpcall; |
| 194 | |
| 10481 | 195 gaim_debug_info("msn", "slpcall timeout (%p)\n", slpcall); |
| 10225 | 196 |
| 10296 | 197 slpcall = data; |
| 10225 | 198 |
| 10296 | 199 if (!slpcall->pending && !slpcall->progress) |
| 200 { | |
| 201 msn_slp_call_destroy(slpcall); | |
| 202 return FALSE; | |
| 203 } | |
| 204 | |
| 205 slpcall->progress = FALSE; | |
| 206 | |
| 207 return TRUE; | |
| 10225 | 208 } |
| 209 | |
| 9193 | 210 MsnSlpCall * |
| 211 msn_slp_process_msg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
| 212 { | |
| 213 MsnSlpCall *slpcall; | |
| 214 const char *body; | |
| 215 gsize body_len; | |
| 216 | |
| 217 slpcall = NULL; | |
| 218 body = slpmsg->buffer; | |
| 219 body_len = slpmsg->size; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
220 |
| 9193 | 221 if (slpmsg->flags == 0x0) |
| 222 { | |
| 223 slpcall = msn_slp_sip_recv(slplink, body, body_len); | |
| 224 } | |
| 225 else if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) | |
| 226 { | |
| 227 slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id); | |
| 228 | |
| 229 if (slpcall != NULL) | |
| 10225 | 230 { |
| 231 if (slpcall->timer) | |
| 232 gaim_timeout_remove(slpcall->timer); | |
| 233 | |
| 9193 | 234 slpcall->cb(slpcall, body, body_len); |
| 10225 | 235 |
| 236 /* TODO: Shall we send a BYE? I don't think so*/ | |
| 237 #if 0 | |
| 238 send_bye(slpcall, "application/x-msnmsgr-sessionclosebody"); | |
| 239 msn_slplink_unleash(slpcall->slplink); | |
| 240 #endif | |
| 241 | |
| 242 slpcall->wasted = TRUE; | |
| 243 } | |
| 9193 | 244 } |
| 245 #if 0 | |
| 246 else if (slpmsg->flags == 0x100) | |
| 247 { | |
| 248 slpcall = slplink->directconn->initial_call; | |
| 249 | |
| 250 if (slpcall != NULL) | |
| 251 msn_slp_call_session_init(slpcall); | |
| 252 } | |
| 253 #endif | |
| 254 | |
| 255 return slpcall; | |
| 256 } |
