Mercurial > pidgin
annotate src/protocols/msn/slpcall.c @ 10261:d4e9ff2edc4e
[gaim-migrate @ 11405]
This should fix segfault bug 1072604. Oops.
committer: Tailor Script <tailor@pidgin.im>
| author | Tim Ringenbach <marv@pidgin.im> |
|---|---|
| date | Thu, 25 Nov 2004 18:35:26 +0000 |
| parents | ecf3ce2e2ab1 |
| children | a7b2fd5efcf2 |
| 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_init(MsnSlpCall *slpcall, MsnSlpCallType type) | |
| 72 { | |
| 73 slpcall->session_id = rand() % 0xFFFFFF00 + 4; | |
| 74 slpcall->id = rand_guid(); | |
| 75 slpcall->type = type; | |
| 76 } | |
| 77 | |
| 78 void | |
| 79 msn_slp_call_session_init(MsnSlpCall *slpcall) | |
| 80 { | |
| 81 MsnSlpSession *slpsession; | |
| 82 | |
| 83 slpsession = msn_slp_session_new(slpcall); | |
| 84 | |
| 85 if (slpcall->session_init_cb) | |
| 86 slpcall->session_init_cb(slpsession); | |
| 87 | |
| 88 slpcall->started = TRUE; | |
| 89 } | |
| 90 | |
| 91 void | |
| 92 msn_slp_call_destroy(MsnSlpCall *slpcall) | |
| 93 { | |
| 94 GList *e; | |
| 95 | |
| 96 g_return_if_fail(slpcall != NULL); | |
| 97 | |
| 10225 | 98 if (slpcall->timer) |
| 99 gaim_timeout_remove(slpcall->timer); | |
| 100 | |
| 9193 | 101 if (slpcall->id != NULL) |
| 102 g_free(slpcall->id); | |
| 103 | |
| 104 if (slpcall->branch != NULL) | |
| 105 g_free(slpcall->branch); | |
| 106 | |
| 107 if (slpcall->data_info != NULL) | |
| 108 g_free(slpcall->data_info); | |
| 109 | |
| 110 slpcall->slplink->slp_calls = | |
| 111 g_list_remove(slpcall->slplink->slp_calls, slpcall); | |
| 112 | |
| 113 for (e = slpcall->slplink->slp_msgs; e != NULL; ) | |
| 114 { | |
| 115 MsnSlpMessage *slpmsg = e->data; | |
| 116 e = e->next; | |
| 117 | |
| 118 g_return_if_fail(slpmsg != NULL); | |
| 119 | |
| 120 if (slpmsg->slpcall == slpcall) | |
| 121 { | |
| 122 #if 1 | |
| 123 msn_slpmsg_destroy(slpmsg); | |
| 124 #else | |
| 125 slpmsg->wasted = TRUE; | |
| 126 #endif | |
| 127 } | |
| 128 } | |
| 129 | |
|
9259
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
130 if (slpcall->end_cb != NULL) |
|
f5f7482678d2
[gaim-migrate @ 10058]
Christian Hammond <chipx86@chipx86.com>
parents:
9198
diff
changeset
|
131 slpcall->end_cb(slpcall); |
| 9193 | 132 |
| 133 g_free(slpcall); | |
| 134 } | |
| 135 | |
| 136 void | |
| 137 msn_slp_call_invite(MsnSlpCall *slpcall, const char *euf_guid, | |
| 138 int app_id, const char *context) | |
| 139 { | |
| 140 MsnSlpLink *slplink; | |
| 141 MsnSlpMessage *slpmsg; | |
| 142 char *header; | |
| 143 char *content; | |
| 144 | |
| 145 g_return_if_fail(slpcall != NULL); | |
| 146 g_return_if_fail(context != NULL); | |
| 147 | |
| 148 slplink = slpcall->slplink; | |
| 149 | |
| 10000 | 150 slpcall->branch = rand_guid(); |
| 9193 | 151 |
| 152 content = g_strdup_printf( | |
| 153 "EUF-GUID: {%s}\r\n" | |
| 154 "SessionID: %lu\r\n" | |
| 155 "AppID: %d\r\n" | |
| 156 "Context: %s\r\n\r\n", | |
| 157 euf_guid, | |
| 158 slpcall->session_id, | |
| 159 app_id, | |
| 160 context); | |
| 161 | |
| 162 header = g_strdup_printf("INVITE MSNMSGR:%s MSNSLP/1.0", | |
| 163 slplink->remote_user); | |
| 164 | |
| 10000 | 165 slpmsg = msn_slpmsg_sip_new(slpcall, 0, header, slpcall->branch, |
| 9193 | 166 "application/x-msnmsgr-sessionreqbody", content); |
| 167 #ifdef DEBUG_SLP | |
| 168 slpmsg->info = "SLP INVITE"; | |
| 169 slpmsg->text_body = TRUE; | |
| 170 #endif | |
| 171 | |
| 172 msn_slplink_send_slpmsg(slplink, slpmsg); | |
| 173 | |
| 174 g_free(header); | |
| 175 g_free(content); | |
| 176 } | |
| 177 | |
| 178 void | |
| 179 msn_slp_call_close(MsnSlpCall *slpcall) | |
| 180 { | |
| 181 g_return_if_fail(slpcall != NULL); | |
| 182 g_return_if_fail(slpcall->slplink != NULL); | |
| 183 | |
| 184 send_bye(slpcall, "application/x-msnmsgr-sessionclosebody"); | |
| 185 msn_slplink_unleash(slpcall->slplink); | |
| 186 msn_slp_call_destroy(slpcall); | |
| 187 } | |
| 188 | |
| 10225 | 189 gboolean |
| 190 msn_slp_call_timeout(gpointer data) | |
| 191 { | |
| 192 gaim_debug_info("msn", "slpcall timeout\n"); | |
| 193 | |
| 194 msn_slp_call_destroy(data); | |
| 195 | |
| 196 return FALSE; | |
| 197 } | |
| 198 | |
| 9193 | 199 MsnSlpCall * |
| 200 msn_slp_process_msg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) | |
| 201 { | |
| 202 MsnSlpCall *slpcall; | |
| 203 const char *body; | |
| 204 gsize body_len; | |
| 205 | |
| 206 slpcall = NULL; | |
| 207 body = slpmsg->buffer; | |
| 208 body_len = slpmsg->size; | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
209 |
| 9193 | 210 if (slpmsg->flags == 0x0) |
| 211 { | |
| 212 slpcall = msn_slp_sip_recv(slplink, body, body_len); | |
| 213 } | |
| 214 else if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) | |
| 215 { | |
| 216 slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id); | |
| 217 | |
| 218 if (slpcall != NULL) | |
| 10225 | 219 { |
| 220 if (slpcall->timer) | |
| 221 gaim_timeout_remove(slpcall->timer); | |
| 222 | |
| 9193 | 223 slpcall->cb(slpcall, body, body_len); |
| 10225 | 224 |
| 225 /* TODO: Shall we send a BYE? I don't think so*/ | |
| 226 #if 0 | |
| 227 send_bye(slpcall, "application/x-msnmsgr-sessionclosebody"); | |
| 228 msn_slplink_unleash(slpcall->slplink); | |
| 229 #endif | |
| 230 | |
| 231 slpcall->wasted = TRUE; | |
| 232 } | |
| 9193 | 233 } |
| 234 #if 0 | |
| 235 else if (slpmsg->flags == 0x100) | |
| 236 { | |
| 237 slpcall = slplink->directconn->initial_call; | |
| 238 | |
| 239 if (slpcall != NULL) | |
| 240 msn_slp_call_session_init(slpcall); | |
| 241 } | |
| 242 #endif | |
| 243 | |
| 10225 | 244 if (slpcall != NULL) |
| 245 { | |
| 246 if (slpcall->timer) | |
| 247 gaim_timeout_remove(slpcall->timer); | |
| 248 | |
| 249 slpcall->timer = gaim_timeout_add(MSN_SLPCALL_TIMEOUT, | |
| 250 msn_slp_call_timeout, slpcall); | |
| 251 } | |
| 252 | |
| 9193 | 253 return slpcall; |
| 254 } |
