Mercurial > pidgin.yaz
changeset 6786:8efafdc38718
[gaim-migrate @ 7325]
It won't work yet, but this is part of the framework for the MSN User
Display image stuff.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sun, 07 Sep 2003 22:35:00 +0000 |
parents | eb8f949095a5 |
children | faa491042c66 |
files | src/protocols/msn/buddyicon.c src/protocols/msn/msg.c src/protocols/msn/msg.h src/protocols/msn/msn.c src/protocols/msn/msn.h src/protocols/msn/msnslp.c src/protocols/msn/msnslp.h src/protocols/msn/servconn.c src/protocols/msn/switchboard.c src/protocols/msn/switchboard.h |
diffstat | 10 files changed, 256 insertions(+), 62 deletions(-) [+] |
line wrap: on
line diff
--- a/src/protocols/msn/buddyicon.c Sun Sep 07 22:06:55 2003 +0000 +++ b/src/protocols/msn/buddyicon.c Sun Sep 07 22:35:00 2003 +0000 @@ -487,11 +487,13 @@ return; /* We don't have an icon to send. */ if (!get_buddy_icon_info(account, NULL, &md5sum, - &file_size, &base64_size)) { + &file_size, &base64_size)) + { return; } - if (file_size > MAX_BUDDY_ICON_FILE_SIZE) { + if (file_size > MAX_BUDDY_ICON_FILE_SIZE) + { gaim_debug(GAIM_DEBUG_ERROR, "msn", "The buddy icon is too large to send. Must be no more " "than %d bytes!\n", MAX_BUDDY_ICON_FILE_SIZE);
--- a/src/protocols/msn/msg.c Sun Sep 07 22:06:55 2003 +0000 +++ b/src/protocols/msn/msg.c Sun Sep 07 22:35:00 2003 +0000 @@ -190,17 +190,20 @@ memcpy(&msg->msnslp_header.total_size, tmp, 4); tmp += 8; memcpy(&msg->msnslp_header.length, tmp, 4); tmp += 4; memcpy(&msg->msnslp_header.flags, tmp, 4); tmp += 4; - memcpy(&msg->msnslp_header.prev_id, tmp, 4); tmp += 4; - memcpy(&msg->msnslp_header.prev_f9, tmp, 4); tmp += 4; - memcpy(&msg->msnslp_header.prev_total_size, tmp, 4); tmp += 8; + memcpy(&msg->msnslp_header.ack_session_id, tmp, 4); tmp += 4; + memcpy(&msg->msnslp_header.ack_unique_id, tmp, 4); tmp += 4; + memcpy(&msg->msnslp_header.ack_length, tmp, 4); tmp += 8; /* Convert to the right endianness */ - msg->msnslp_header.session_id = ntohs(msg->msnslp_header.session_id); - msg->msnslp_header.id = ntohs(msg->msnslp_header.id); - msg->msnslp_header.length = ntohs(msg->msnslp_header.length); - msg->msnslp_header.flags = ntohs(msg->msnslp_header.flags); - msg->msnslp_header.prev_id = ntohs(msg->msnslp_header.prev_id); - msg->msnslp_header.prev_f9 = ntohs(msg->msnslp_header.prev_f9); + msg->msnslp_header.session_id = ntohl(msg->msnslp_header.session_id); + msg->msnslp_header.id = ntohl(msg->msnslp_header.id); + msg->msnslp_header.length = ntohl(msg->msnslp_header.length); + msg->msnslp_header.flags = ntohl(msg->msnslp_header.flags); + msg->msnslp_header.ack_length = ntohl(msg->msnslp_header.ack_length); + msg->msnslp_header.ack_session_id = + ntohl(msg->msnslp_header.ack_session_id); + msg->msnslp_header.ack_unique_id = + ntohl(msg->msnslp_header.ack_unique_id); /* Import the footer. */ msg->msnslp_footer.app_id = (long)footer; @@ -351,22 +354,22 @@ { char *c; char blank[4]; - int session_id, id, offset, total_size, length, flags; - int prev_id, prev_f9, prev_total_size; + long session_id, id, offset, total_size, length, flags; + long ack_session_id, ack_unique_id, ack_length; memcpy(blank, 0, 4); c = str + strlen(str); - session_id = htons(msg->msnslp_header.session_id); - id = htons(msg->msnslp_header.id); - offset = htons(msg->msnslp_header.offset); - total_size = htons(msg->msnslp_header.total_size); - length = htons(msg->msnslp_header.length); - flags = htons(msg->msnslp_header.flags); - prev_id = htons(msg->msnslp_header.prev_id); - prev_f9 = htons(msg->msnslp_header.prev_f9); - prev_total_size = htons(msg->msnslp_header.prev_total_size); + session_id = htonl(msg->msnslp_header.session_id); + id = htonl(msg->msnslp_header.id); + offset = htonl(msg->msnslp_header.offset); + total_size = htonl(msg->msnslp_header.total_size); + length = htonl(msg->msnslp_header.length); + flags = htonl(msg->msnslp_header.flags); + ack_session_id = htonl(msg->msnslp_header.ack_session_id); + ack_unique_id = htonl(msg->msnslp_header.ack_unique_id); + ack_length = htonl(msg->msnslp_header.ack_length); memcpy(c, &session_id, 4); c += 4; memcpy(c, &id, 4); c += 4; @@ -376,9 +379,9 @@ memcpy(c, blank, 4); c += 4; memcpy(c, &length, 4); c += 4; memcpy(c, &flags, 4); c += 4; - memcpy(c, &prev_id, 4); c += 4; - memcpy(c, &prev_f9, 4); c += 4; - memcpy(c, &prev_total_size, 4); c += 4; + memcpy(c, &ack_session_id, 4); c += 4; + memcpy(c, &ack_unique_id, 4); c += 4; + memcpy(c, &ack_length, 4); c += 4; memcpy(c, blank, 4); c += 4; strncpy(c, msn_message_get_body(msg), len);
--- a/src/protocols/msn/msg.h Sun Sep 07 22:06:55 2003 +0000 +++ b/src/protocols/msn/msg.h Sun Sep 07 22:35:00 2003 +0000 @@ -24,10 +24,29 @@ typedef struct _MsnMessage MsnMessage; -#include "msnslp.h" #include "session.h" #include "user.h" +typedef struct +{ + long session_id; + long id; + long offset; + long total_size; + long length; + long flags; + long ack_session_id; + long ack_unique_id; + long ack_length; + +} MsnSlpHeader; + +typedef struct +{ + long app_id; + +} MsnSlpFooter; + /** * A message. */
--- a/src/protocols/msn/msn.c Sun Sep 07 22:06:55 2003 +0000 +++ b/src/protocols/msn/msn.c Sun Sep 07 22:35:00 2003 +0000 @@ -1028,16 +1028,17 @@ const char *old_group_name, const char *new_group_name) { MsnSession *session = gc->proto_data; + MsnGroup *old_group, *new_group; MsnUser *user; char outparams[MSN_BUF_LEN]; - MsnGroup *old_group, *new_group; old_group = msn_groups_find_with_name(session->groups, old_group_name); new_group = msn_groups_find_with_name(session->groups, new_group_name); user = msn_users_find_with_passport(session->users, who); - msn_user_remove_group_id(user, msn_group_get_id(old_group)); + if (old_group != NULL) + msn_user_remove_group_id(user, msn_group_get_id(old_group)); if (new_group == NULL) { g_snprintf(outparams, sizeof(outparams), "%s 0",
--- a/src/protocols/msn/msn.h Sun Sep 07 22:06:55 2003 +0000 +++ b/src/protocols/msn/msn.h Sun Sep 07 22:35:00 2003 +0000 @@ -71,8 +71,7 @@ #define MSN_CLIENTINFO \ "Client-Name: Gaim/" VERSION "\r\n" \ - "Chat-Logging: Y\r\n" \ - "Buddy-Icons: 1\r\n" + "Chat-Logging: Y\r\n" typedef enum
--- a/src/protocols/msn/msnslp.c Sun Sep 07 22:06:55 2003 +0000 +++ b/src/protocols/msn/msnslp.c Sun Sep 07 22:35:00 2003 +0000 @@ -19,8 +19,30 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "msn.h" #include "msnslp.h" +static void +send_ack(MsnSlpSession *slpsession, MsnMessage *acked_msg) +{ + MsnMessage *msg; + + msg = msn_message_new(); + + msg->msnslp_message = TRUE; + + msg->msnslp_header.length = acked_msg->msnslp_header.length; + msg->msnslp_header.flags = 0x02; + msg->msnslp_header.ack_session_id = + acked_msg->msnslp_header.ack_session_id; + msg->msnslp_header.ack_unique_id = + acked_msg->msnslp_header.id; + msg->msnslp_header.ack_length = acked_msg->msnslp_header.length; + + /* Send this puppy. */ + msn_slp_session_send_msg(slpsession, msg); +} + MsnSlpSession * msn_slp_session_new(MsnSwitchBoard *swboard, gboolean local_initiated) { @@ -44,10 +66,135 @@ g_free(session); } +gboolean +msn_slp_session_msg_received(MsnSlpSession *slpsession, MsnMessage *msg) +{ + const char *body; + + g_return_val_if_fail(slpsession != NULL, TRUE); + g_return_val_if_fail(msg != NULL, TRUE); + g_return_val_if_fail(msg->msnslp_message, TRUE); + g_return_val_if_fail(!strcmp(msn_message_get_content_type(msg), + "application/x-msnmsgrp2p"), TRUE); + + body = msn_message_get_body(msg); + + if (strlen(body) == 0) + { + /* ACK. Ignore it. */ + return FALSE; + } + + /* Now send an ack, since we got this. */ + send_ack(slpsession, msg); + + return FALSE; +} + void -msn_slp_session_send_msg(MsnSlpSession *session, MsnMessage *msg) +msn_slp_session_send_msg(MsnSlpSession *slpsession, MsnMessage *msg) +{ + g_return_if_fail(slpsession != NULL); + g_return_if_fail(msg != NULL); + g_return_if_fail(msg->msnslp_message); + + msg->msnslp_header.session_id = slpsession->session_id; + + if (slpsession->base_id == 0) + { + slpsession->base_id = rand() % 0xFFFFFF00 + 4; + slpsession->prev_msg_id = slpsession->base_id; + } + else + slpsession->prev_msg_id = ++slpsession->base_id; + + msg->msnslp_header.id = slpsession->prev_msg_id; + msg->msnslp_header.ack_session_id = rand() % 0xFFFFFF00; + msg->msnslp_header.total_size = strlen(msn_message_get_body(msg)); + + msn_message_set_charset(msg, NULL); + + msn_message_set_flag(msg, 'D'); + msn_message_set_content_type(msg, "application/x-msnmsgrp2p"); + msn_message_set_attr(msg, "P2P-Dest", + msn_user_get_passport(msn_message_get_receiver(msg))); + + msn_switchboard_send_msg(slpsession->swboard, msg); +} + +void +msn_slp_session_request_user_display(MsnSlpSession *slpsession, + const MsnUser *localUser, + const MsnUser *remoteUser, + const MsnObject *obj) { - g_return_if_fail(session != NULL); - g_return_if_fail(msg != NULL); + MsnMessage *invite_msg; + char *msnobj_data; + char *msnobj_base64; + char *content; + char *header; + + g_return_if_fail(slpsession != NULL); + g_return_if_fail(localUser != NULL); + g_return_if_fail(remoteUser != NULL); + g_return_if_fail(obj != NULL); + + msnobj_data = msn_object_to_string(obj); + msnobj_base64 = tobase64(msnobj_data, strlen(msnobj_data)); + g_free(msnobj_data); + + if (slpsession->session_id == 0) + slpsession->session_id = rand() % 0xFFFFFF00; + + content = g_strdup_printf( + "EUF-GUID: {A4268EEC-FEC5-49E5-95C3-F126696BDBF6}\r\n" + "SessionID: %ld\r\n" + "AppID: 1\r\n" + "Context: %s", + slpsession->session_id, + msnobj_base64); + + g_free(msnobj_base64); + header = g_strdup_printf( + "INVITE MSNMSGR:%s MSNSLP/1.0\r\n" + "To: <msnmsgr:%s>\r\n" + "From: <msnmsgr:%s>\r\n" + "Via: MSNSLP/1.0/TLP ;branch={33517CE4-02FC-4428-B6F4-39927229B722}\r\n" + "CSeq: 0\r\n" + "Call-ID: {9D79AE57-1BD5-444B-B14E-3FC9BB2B5D58}\r\n" + "Max-Forwards: 0\r\n" + "Content-Type: application/x-msnmsgr-sessionreqbody\r\n" + "Content-Length: %d\r\n" + "\r\n" + "%s" + "\r\n\r\n", + msn_user_get_passport(remoteUser), + msn_user_get_passport(localUser), + msn_user_get_passport(remoteUser), + strlen(content) + 5, + content); + + invite_msg = msn_message_new(); + + msn_slp_session_send_msg(slpsession, invite_msg); + + msn_message_destroy(invite_msg); } + +gboolean +msn_p2p_msg(MsnServConn *servconn, MsnMessage *msg) +{ + MsnSwitchBoard *swboard = servconn->data; + gboolean session_ended = FALSE; + + if (swboard->slp_session == NULL) + swboard->slp_session = msn_slp_session_new(swboard, TRUE); + + session_ended = msn_slp_session_msg_received(swboard->slp_session, msg); + + if (session_ended) + msn_slp_session_destroy(swboard->slp_session); + + return FALSE; +}
--- a/src/protocols/msn/msnslp.h Sun Sep 07 22:06:55 2003 +0000 +++ b/src/protocols/msn/msnslp.h Sun Sep 07 22:35:00 2003 +0000 @@ -22,38 +22,23 @@ #ifndef _MSN_SLP_H_ #define _MSN_SLP_H_ -typedef struct -{ - long session_id; - long id; - long offset; - long total_size; - long length; - long flags; - long prev_id; - long prev_f9; - long prev_total_size; +typedef struct _MsnSlpSession MsnSlpSession; -} MsnSlpHeader; - -typedef struct -{ - long app_id; - -} MsnSlpFooter; +#include "msnobject.h" +#include "user.h" #include "switchboard.h" -typedef struct +struct _MsnSlpSession { gboolean local_initiated; MsnSwitchBoard *swboard; - int session_id; - int prev_msg_id; - -} MsnSlpSession; + long session_id; + long base_id; + long prev_msg_id; +}; /** * Creates a MSNSLP session. @@ -76,6 +61,17 @@ void msn_slp_session_destroy(MsnSlpSession *slpsession); /** + * Notifies the MSNSLP session handle that a message was received. + * + * @param slpsession The MSNSLP session. + * @param msg The message. + * + * @return TRUE if the session was closed, or FALSE otherwise. + */ +gboolean msn_slp_session_msg_received(MsnSlpSession *slpsession, + MsnMessage *msg); + +/** * Sends a message over a MSNSLP session. * * @param slpsession The MSNSLP session to send the message over. @@ -83,4 +79,27 @@ */ void msn_slp_session_send_msg(MsnSlpSession *session, MsnMessage *msg); +/** + * Requests a User Display image over a MSNSLP session. + * + * @param slpsession The MSNSLP session to request the image over. + * @param localUser The local user initiating the invite. + * @param remoteUser The remote user the invite is sent to. + * @param obj The MSNObject representing the user display info. + */ +void msn_slp_session_request_user_display(MsnSlpSession *session, + const MsnUser *localUser, + const MsnUser *remoteUser, + const MsnObject *obj); + +/** + * Processes application/x-msnmsgrp2p messages. + * + * @param servconn The server connection. + * @param msg The message. + * + * @return TRUE + */ +gboolean msn_p2p_msg(MsnServConn *servconn, MsnMessage *msg); + #endif /* _MSN_SLP_H_ */
--- a/src/protocols/msn/servconn.c Sun Sep 07 22:06:55 2003 +0000 +++ b/src/protocols/msn/servconn.c Sun Sep 07 22:35:00 2003 +0000 @@ -278,9 +278,6 @@ if (servconn->server != NULL) g_free(servconn->server); - g_hash_table_destroy(servconn->commands); - g_hash_table_destroy(servconn->msg_types); - g_free(servconn); }
--- a/src/protocols/msn/switchboard.c Sun Sep 07 22:06:55 2003 +0000 +++ b/src/protocols/msn/switchboard.c Sun Sep 07 22:35:00 2003 +0000 @@ -20,6 +20,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "msn.h" +#include "msnslp.h" #include "prefs.h" #include "switchboard.h" #include "utils.h" @@ -362,7 +363,8 @@ clientcaps = msn_message_get_hashtable_from_body(msg); - if (swboard->chat == NULL) { + if (swboard->chat == NULL && session->protocol_ver < 8) + { if ((value = g_hash_table_lookup(clientcaps, "Buddy-Icons")) != NULL) msn_buddy_icon_invite(swboard); } @@ -464,6 +466,8 @@ clientcaps_msg); msn_servconn_register_msg_type(servconn, "application/x-buddyicon", msn_buddy_icon_msg); + msn_servconn_register_msg_type(servconn, "application/x-msnmsgrp2p", + msn_p2p_msg); /* Save these for future use. */ switchboard_commands = servconn->commands;
--- a/src/protocols/msn/switchboard.h Sun Sep 07 22:06:55 2003 +0000 +++ b/src/protocols/msn/switchboard.h Sun Sep 07 22:35:00 2003 +0000 @@ -26,10 +26,11 @@ #include "conversation.h" -#include "servconn.h" +#include "buddyicon.h" #include "msg.h" +#include "msnslp.h" +#include "servconn.h" #include "user.h" -#include "buddyicon.h" struct _MsnSwitchBoard { @@ -55,6 +56,8 @@ gboolean hidden; + MsnSlpSession *slp_session; + MsnBuddyIconXfer *buddy_icon_xfer; };