| 1 /** |
|
| 2 * @file slpcall.c SLP Call Functions |
|
| 3 * |
|
| 4 * gaim |
|
| 5 * |
|
| 6 * Gaim is the legal property of its developers, whose names are too numerous |
|
| 7 * to list here. Please refer to the COPYRIGHT file distributed with this |
|
| 8 * source distribution. |
|
| 9 * |
|
| 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 /* #define MSN_DEBUG_SLPCALL */ |
|
| 31 |
|
| 32 /************************************************************************** |
|
| 33 * Util |
|
| 34 **************************************************************************/ |
|
| 35 |
|
| 36 static char * |
|
| 37 rand_guid() |
|
| 38 { |
|
| 39 return g_strdup_printf("%4X%4X-%4X-%4X-%4X-%4X%4X%4X", |
|
| 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 rand() % 0xAAFF + 0x1111, |
|
| 47 rand() % 0xAAFF + 0x1111); |
|
| 48 } |
|
| 49 |
|
| 50 /************************************************************************** |
|
| 51 * Main |
|
| 52 **************************************************************************/ |
|
| 53 |
|
| 54 MsnSlpCall * |
|
| 55 msn_slp_call_new(MsnSlpLink *slplink) |
|
| 56 { |
|
| 57 MsnSlpCall *slpcall; |
|
| 58 |
|
| 59 g_return_val_if_fail(slplink != NULL, NULL); |
|
| 60 |
|
| 61 slpcall = g_new0(MsnSlpCall, 1); |
|
| 62 |
|
| 63 #ifdef MSN_DEBUG_SLPCALL |
|
| 64 gaim_debug_info("msn", "slpcall_new: slpcall(%p)\n", slpcall); |
|
| 65 #endif |
|
| 66 |
|
| 67 slpcall->slplink = slplink; |
|
| 68 |
|
| 69 msn_slplink_add_slpcall(slplink, slpcall); |
|
| 70 |
|
| 71 slpcall->timer = gaim_timeout_add(MSN_SLPCALL_TIMEOUT, msn_slp_call_timeout, slpcall); |
|
| 72 |
|
| 73 return slpcall; |
|
| 74 } |
|
| 75 |
|
| 76 void |
|
| 77 msn_slp_call_destroy(MsnSlpCall *slpcall) |
|
| 78 { |
|
| 79 GList *e; |
|
| 80 |
|
| 81 #ifdef MSN_DEBUG_SLPCALL |
|
| 82 gaim_debug_info("msn", "slpcall_destroy: slpcall(%p)\n", slpcall); |
|
| 83 #endif |
|
| 84 |
|
| 85 g_return_if_fail(slpcall != NULL); |
|
| 86 |
|
| 87 if (slpcall->timer) |
|
| 88 gaim_timeout_remove(slpcall->timer); |
|
| 89 |
|
| 90 if (slpcall->id != NULL) |
|
| 91 g_free(slpcall->id); |
|
| 92 |
|
| 93 if (slpcall->branch != NULL) |
|
| 94 g_free(slpcall->branch); |
|
| 95 |
|
| 96 if (slpcall->data_info != NULL) |
|
| 97 g_free(slpcall->data_info); |
|
| 98 |
|
| 99 for (e = slpcall->slplink->slp_msgs; e != NULL; ) |
|
| 100 { |
|
| 101 MsnSlpMessage *slpmsg = e->data; |
|
| 102 e = e->next; |
|
| 103 |
|
| 104 #ifdef MSN_DEBUG_SLPCALL_VERBOSE |
|
| 105 gaim_debug_info("msn", "slpcall_destroy: trying slpmsg(%p)\n", |
|
| 106 slpmsg); |
|
| 107 #endif |
|
| 108 |
|
| 109 if (slpmsg->slpcall == slpcall) |
|
| 110 { |
|
| 111 msn_slpmsg_destroy(slpmsg); |
|
| 112 } |
|
| 113 } |
|
| 114 |
|
| 115 /* Call the end_cb before removing the slpcall, as the end_cb may need the slplink */ |
|
| 116 if (slpcall->end_cb != NULL) |
|
| 117 slpcall->end_cb(slpcall); |
|
| 118 |
|
| 119 msn_slplink_remove_slpcall(slpcall->slplink, slpcall); |
|
| 120 |
|
| 121 g_free(slpcall); |
|
| 122 } |
|
| 123 |
|
| 124 void |
|
| 125 msn_slp_call_init(MsnSlpCall *slpcall, MsnSlpCallType type) |
|
| 126 { |
|
| 127 slpcall->session_id = rand() % 0xFFFFFF00 + 4; |
|
| 128 slpcall->id = rand_guid(); |
|
| 129 slpcall->type = type; |
|
| 130 } |
|
| 131 |
|
| 132 void |
|
| 133 msn_slp_call_session_init(MsnSlpCall *slpcall) |
|
| 134 { |
|
| 135 MsnSlpSession *slpsession; |
|
| 136 |
|
| 137 slpsession = msn_slp_session_new(slpcall); |
|
| 138 |
|
| 139 if (slpcall->session_init_cb) |
|
| 140 slpcall->session_init_cb(slpsession); |
|
| 141 |
|
| 142 slpcall->started = TRUE; |
|
| 143 } |
|
| 144 |
|
| 145 void |
|
| 146 msn_slp_call_invite(MsnSlpCall *slpcall, const char *euf_guid, |
|
| 147 int app_id, const char *context) |
|
| 148 { |
|
| 149 MsnSlpLink *slplink; |
|
| 150 MsnSlpMessage *slpmsg; |
|
| 151 char *header; |
|
| 152 char *content; |
|
| 153 |
|
| 154 g_return_if_fail(slpcall != NULL); |
|
| 155 g_return_if_fail(context != NULL); |
|
| 156 |
|
| 157 slplink = slpcall->slplink; |
|
| 158 |
|
| 159 slpcall->branch = rand_guid(); |
|
| 160 |
|
| 161 content = g_strdup_printf( |
|
| 162 "EUF-GUID: {%s}\r\n" |
|
| 163 "SessionID: %lu\r\n" |
|
| 164 "AppID: %d\r\n" |
|
| 165 "Context: %s\r\n\r\n", |
|
| 166 euf_guid, |
|
| 167 slpcall->session_id, |
|
| 168 app_id, |
|
| 169 context); |
|
| 170 |
|
| 171 header = g_strdup_printf("INVITE MSNMSGR:%s MSNSLP/1.0", |
|
| 172 slplink->remote_user); |
|
| 173 |
|
| 174 slpmsg = msn_slpmsg_sip_new(slpcall, 0, header, slpcall->branch, |
|
| 175 "application/x-msnmsgr-sessionreqbody", content); |
|
| 176 |
|
| 177 #ifdef MSN_DEBUG_SLP |
|
| 178 slpmsg->info = "SLP INVITE"; |
|
| 179 slpmsg->text_body = TRUE; |
|
| 180 #endif |
|
| 181 |
|
| 182 msn_slplink_send_slpmsg(slplink, slpmsg); |
|
| 183 |
|
| 184 g_free(header); |
|
| 185 g_free(content); |
|
| 186 } |
|
| 187 |
|
| 188 void |
|
| 189 msn_slp_call_close(MsnSlpCall *slpcall) |
|
| 190 { |
|
| 191 g_return_if_fail(slpcall != NULL); |
|
| 192 g_return_if_fail(slpcall->slplink != NULL); |
|
| 193 |
|
| 194 send_bye(slpcall, "application/x-msnmsgr-sessionclosebody"); |
|
| 195 msn_slplink_unleash(slpcall->slplink); |
|
| 196 msn_slp_call_destroy(slpcall); |
|
| 197 } |
|
| 198 |
|
| 199 gboolean |
|
| 200 msn_slp_call_timeout(gpointer data) |
|
| 201 { |
|
| 202 MsnSlpCall *slpcall; |
|
| 203 |
|
| 204 slpcall = data; |
|
| 205 |
|
| 206 #ifdef MSN_DEBUG_SLPCALL |
|
| 207 gaim_debug_info("msn", "slpcall_timeout: slpcall(%p)\n", slpcall); |
|
| 208 #endif |
|
| 209 |
|
| 210 if (!slpcall->pending && !slpcall->progress) |
|
| 211 { |
|
| 212 msn_slp_call_destroy(slpcall); |
|
| 213 return FALSE; |
|
| 214 } |
|
| 215 |
|
| 216 slpcall->progress = FALSE; |
|
| 217 |
|
| 218 return TRUE; |
|
| 219 } |
|
| 220 |
|
| 221 MsnSlpCall * |
|
| 222 msn_slp_process_msg(MsnSlpLink *slplink, MsnSlpMessage *slpmsg) |
|
| 223 { |
|
| 224 MsnSlpCall *slpcall; |
|
| 225 const guchar *body; |
|
| 226 gsize body_len; |
|
| 227 |
|
| 228 slpcall = NULL; |
|
| 229 body = slpmsg->buffer; |
|
| 230 body_len = slpmsg->size; |
|
| 231 |
|
| 232 if (slpmsg->flags == 0x0) |
|
| 233 { |
|
| 234 char *body_str; |
|
| 235 |
|
| 236 body_str = g_strndup((const char *)body, body_len); |
|
| 237 slpcall = msn_slp_sip_recv(slplink, body_str); |
|
| 238 g_free(body_str); |
|
| 239 } |
|
| 240 else if (slpmsg->flags == 0x20 || slpmsg->flags == 0x1000030) |
|
| 241 { |
|
| 242 slpcall = msn_slplink_find_slp_call_with_session_id(slplink, slpmsg->session_id); |
|
| 243 |
|
| 244 if (slpcall != NULL) |
|
| 245 { |
|
| 246 if (slpcall->timer) |
|
| 247 gaim_timeout_remove(slpcall->timer); |
|
| 248 |
|
| 249 slpcall->cb(slpcall, body, body_len); |
|
| 250 |
|
| 251 slpcall->wasted = TRUE; |
|
| 252 } |
|
| 253 } |
|
| 254 #if 0 |
|
| 255 else if (slpmsg->flags == 0x100) |
|
| 256 { |
|
| 257 slpcall = slplink->directconn->initial_call; |
|
| 258 |
|
| 259 if (slpcall != NULL) |
|
| 260 msn_slp_call_session_init(slpcall); |
|
| 261 } |
|
| 262 #endif |
|
| 263 |
|
| 264 return slpcall; |
|
| 265 } |
|