aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2009-08-18 01:03:14 +0100
committerThomas White <taw@bitwiz.org.uk>2009-08-18 01:03:14 +0100
commita5e90200713d7b17d3d4956bd64d5af2a66a999f (patch)
treee7618f6e6eae5b95e075942f98c1c37ee9163b6c
parent225c75c056cf7d3466c77840c66312bf54094988 (diff)
Whitespace
-rw-r--r--src/msnp2p.c328
1 files changed, 164 insertions, 164 deletions
diff --git a/src/msnp2p.c b/src/msnp2p.c
index 3a77951..a6ca83f 100644
--- a/src/msnp2p.c
+++ b/src/msnp2p.c
@@ -8,17 +8,17 @@
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 dated June, 1991.
+ * the Free Software Foundation; version 2 dated June, 1991.
*
* This package is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this package; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * 02111-1307, USA.
*
*/
@@ -65,7 +65,7 @@ struct _mpsession {
MSNP2P_TYPE_INK,
MSNP2P_TYPE_FT
} type;
- unsigned int session_id;
+ unsigned int session_id;
FILE *fh;
char *save_filename;
char *sha1d; /* The SHA1D field from the MSNObject, after xml_killillegalchars. */
@@ -89,14 +89,14 @@ struct _mpheader {
uint32_t ack_id;
uint32_t ack_sess;
uint64_t ack_size;
-
+
};
typedef struct _mpheader MpHeader;
static MpSession *msnp2p_new() {
MpSession *mpsession = malloc(sizeof(MpSession));
-
+
mpsession->save_filename = NULL;
mpsession->sha1d = NULL;
mpsession->via = NULL;
@@ -141,7 +141,7 @@ static gboolean msnp2p_closesession(MpSession *mpsession) {
msnp2p_list = g_list_remove(msnp2p_list, mpsession);
free(mpsession);
-
+
return FALSE;
}
@@ -168,40 +168,40 @@ static void msnp2p_send(SbSession *session, MpHeader mpheader, const char *usern
/* Calculate the total message length. */
total_message_length = strlen(msnp2p_text) + 48 + payload_length + 4;
-
+
/* Snippet */
message_stub = malloc(9);
if ( message_stub == NULL ) {
-
+
debug_print("MP: Not enough memory to send MSNP2P message.\n");
free(msnp2p_text);
return;
-
+
}
assert(total_message_length < 10000); /* i.e. fits into four digits. */
sprintf(message_stub, "D %i\r\n", total_message_length);
stub_length = strlen(message_stub);
-
+
final = malloc(stub_length + strlen(msnp2p_text) + 48 + payload_length + 4);
if ( final == NULL ) {
-
+
debug_print("MP: Not enough memory to send MSNP2P message.\n");
free(message_stub);
free(msnp2p_text);
return;
-
+
}
-
+
strcpy(final, message_stub);
free(message_stub);
strcat(final, msnp2p_text);
free(msnp2p_text);
sf = strlen(final);
-
+
memcpy (final+sf, &mpheader, 48);
memcpy (final+sf+48, payload, payload_length);
*((int *)(final+sf+48+payload_length)) = htonl(app_id);
-
+
sbprotocol_sendtr_nonewline(session, "MSG", final, total_message_length+stub_length);
free(final);
@@ -212,7 +212,7 @@ static gint msnp2p_compare_identifier(MpSession *mpsession, unsigned int *identi
if ( mpsession->baseidentifier == *identifier ) {
return 0;
}
-
+
return 1;
}
@@ -222,7 +222,7 @@ static gint msnp2p_compare_parent(MpSession *mpsession, SbSession **parent) {
if ( mpsession->parent == *parent ) {
return 0;
}
-
+
return 1;
}
@@ -244,9 +244,9 @@ static gint msnp2p_compare_callid(MpSession *mpsession, char *call_id) {
return 0;
}
}
-
+
return 1;
-
+
}
static gint msnp2p_compare_savefilename(MpSession *mpsession, char *save_filename) {
@@ -256,9 +256,9 @@ static gint msnp2p_compare_savefilename(MpSession *mpsession, char *save_filenam
return 0;
}
}
-
+
return 1;
-
+
}
/*static gint msnp2p_compare_sha1d(MpSession *mpsession, char *sha1d) {
@@ -268,9 +268,9 @@ static gint msnp2p_compare_savefilename(MpSession *mpsession, char *save_filenam
return 0;
}
}
-
+
return 1;
-
+
}*/
static MpSession *msnp2p_find_identifier(unsigned long int identifier) {
@@ -278,11 +278,11 @@ static MpSession *msnp2p_find_identifier(unsigned long int identifier) {
GList *result;
result = g_list_find_custom(msnp2p_list, &identifier, (GCompareFunc)msnp2p_compare_identifier);
-
+
if ( result != NULL ) {
return (MpSession *)result->data;
}
-
+
return NULL;
}
@@ -292,11 +292,11 @@ static MpSession *msnp2p_find_sessionid(unsigned long int sessionid) {
GList *result;
result = g_list_find_custom(msnp2p_list, &sessionid, (GCompareFunc)msnp2p_compare_sessionid);
-
+
if ( result != NULL ) {
return (MpSession *)result->data;
}
-
+
return NULL;
}
@@ -306,11 +306,11 @@ static MpSession *msnp2p_find_callid(char *callid) {
GList *result;
result = g_list_find_custom(msnp2p_list, callid, (GCompareFunc)msnp2p_compare_callid);
-
+
if ( result != NULL ) {
return (MpSession *)result->data;
}
-
+
return NULL;
}
@@ -329,7 +329,7 @@ static MpSession *msnp2p_check_ok(const char *msnslp) {
char *session_id_string;
MpSession *mpsession;
-
+
session_id_string = mime_getfield_anywhere(msnslp, "SessionID");
if ( strlen(session_id_string) == 0 ) {
debug_print("MP: Couldn't find SessionID field.\n");
@@ -338,18 +338,18 @@ static MpSession *msnp2p_check_ok(const char *msnslp) {
}
mpsession = msnp2p_find_sessionid(atoi(session_id_string));
free(session_id_string);
-
+
if ( strncmp(msnslp, "MSNSLP/1.0 200 OK", 17) == 0 ) {
-
+
debug_print("MP: Got MSNSLP/1.0 200 OK - ");
if ( mpsession == NULL ) {
debug_print("but session not found.\n");
} else {
debug_print("and session found.\n");
}
-
+
}
-
+
return mpsession;
}
@@ -358,7 +358,7 @@ static int msnp2p_check_bye(SbSession *session, const char *msnslp, MpHeader *mp
char *callid_string;
MpSession *mpsession;
-
+
callid_string = mime_getfield_anywhere(msnslp, "Call-ID");
if ( callid_string == NULL ) {
debug_print("MP: Couldn't find Call-ID field.\n");
@@ -366,18 +366,18 @@ static int msnp2p_check_bye(SbSession *session, const char *msnslp, MpHeader *mp
}
mpsession = msnp2p_find_callid(callid_string);
free(callid_string);
-
+
if ( strncmp(msnslp, "BYE MSNMSGR", 11) == 0 ) {
-
+
debug_print("MP: Got BYE MSNMSGR - ");
if ( mpsession == NULL ) {
debug_print("but session not found.\n");
} else {
-
+
MpHeader acknowledgement;
-
+
debug_print("and session found.\n");
-
+
/* Send BYE ACK message. */
acknowledgement.session_id = 0;
acknowledgement.identifier = GINT32_TO_LE(mpsession->baseidentifier + mpsession->id_increment);
@@ -389,20 +389,20 @@ static int msnp2p_check_bye(SbSession *session, const char *msnslp, MpHeader *mp
acknowledgement.ack_sess = mpheader->identifier;
acknowledgement.ack_id = mpheader->ack_sess;
acknowledgement.ack_size = mpheader->size;
-
+
debug_print("MP: Sending BYE ACK\n");
msnp2p_send(session, acknowledgement, mpsession->username, "", 0, 0);
-
+
/* Delay before deletion allows straggling packets to be collected. */
debug_print("MP: Closing MSNP2P session in ten seconds...\n");
mpsession->delete_timeout = g_timeout_add(10000, (GSourceFunc)msnp2p_closesession, mpsession);
-
+
return 1;
-
+
}
-
+
}
-
+
return 0;
}
@@ -413,15 +413,15 @@ static unsigned int msnp2p_cookie() {
unsigned int seed;
float num;
unsigned int val;
-
+
fh = fopen("/dev/urandom", "r");
fread(&seed, sizeof(seed), 1, fh);
fclose(fh);
srand(seed);
-
+
num = (float)rand() / (float)RAND_MAX;
val = (num * 16777216)+8;
-
+
return val;
}
@@ -456,13 +456,13 @@ static MpSession *msnp2p_send_dp(MpSession *mpsession, SbSession *session, const
free(mpsession);
return NULL;
}
-
+
request_details = malloc(26);
debug_print("MP: New session ID=%i\n", mpsession->session_id);
strcpy(request_details, "SessionID: ");
sprintf(request_details+strlen(request_details), "%i\r\n\r\n", mpsession->session_id);
request_details_length = strlen(request_details);
-
+
msnslp_block = malloc( 176 + strlen(options_username()) + strlen(mpsession->username) + strlen(mpsession->via) + strlen(mpsession->call_id) + strlen(request_details) );
strcpy(msnslp_block, "MSNSLP/1.0 200 OK\r\nTo: <msnmsgr:");
strncat(msnslp_block, mpsession->username, 64);
@@ -478,7 +478,7 @@ static MpSession *msnp2p_send_dp(MpSession *mpsession, SbSession *session, const
strcat(msnslp_block, "\r\n\r\n");
strcat(msnslp_block, request_details);
free(request_details);
-
+
msnslp_length = strlen(msnslp_block);
msnp2p_binary.session_id = 0;
@@ -494,7 +494,7 @@ static MpSession *msnp2p_send_dp(MpSession *mpsession, SbSession *session, const
debug_print("MP: Sending 200 OK message\n");
msnp2p_send(session, msnp2p_binary, mpsession->username, msnslp_block, strlen(msnslp_block)+1, 0);
free(msnslp_block);
-
+
local_avatar = avatars_local();
glob(local_avatar, GLOB_TILDE, NULL, &glob_result);
free(local_avatar);
@@ -505,10 +505,10 @@ static MpSession *msnp2p_send_dp(MpSession *mpsession, SbSession *session, const
free(mpsession);
return NULL;
}
-
+
size = (int)statbuf->st_size;
assert(size > 0);
-
+
fh = fopen(glob_result.gl_pathv[0], "r");
if ( fh == NULL ) {
debug_print("MP: Couldn't open avatar file.\n");
@@ -526,7 +526,7 @@ static MpSession *msnp2p_send_dp(MpSession *mpsession, SbSession *session, const
debug_print("MP: Read %i bytes of avatar file\n", readval);
fclose(fh);
globfree(&glob_result);
-
+
msnp2p_binary.session_id = GINT32_TO_LE(mpsession->session_id);
msnp2p_binary.identifier = GINT32_TO_LE(mpsession->baseidentifier + mpsession->id_increment);
msnp2p_inc(mpsession);
@@ -540,7 +540,7 @@ static MpSession *msnp2p_send_dp(MpSession *mpsession, SbSession *session, const
zero = 0;
debug_print("MP: Sending data preparation message\n");
msnp2p_send(session, msnp2p_binary, mpsession->username, (char *)&zero, 4, 1);
-
+
msnp2p_binary.session_id = GINT32_TO_LE(mpsession->session_id);
msnp2p_binary.identifier = GINT32_TO_LE(mpsession->baseidentifier + mpsession->id_increment);
msnp2p_inc(mpsession);
@@ -548,21 +548,21 @@ static MpSession *msnp2p_send_dp(MpSession *mpsession, SbSession *session, const
msnp2p_binary.flags = GINT32_TO_LE(0x20);
msnp2p_binary.ack_id = 0;
msnp2p_binary.ack_size = 0;
-
+
for ( file_offs=0; file_offs<size; file_offs+=1202 ) {
-
+
msnp2p_binary.offset = file_offs;
if ( (size-file_offs) > 1201 ) {
msnp2p_binary.size = GINT64_TO_LE(1202);
} else {
msnp2p_binary.size = GINT64_TO_LE((size-file_offs) % 1202);
}
- msnp2p_binary.ack_sess = msnp2p_cookie();
+ msnp2p_binary.ack_sess = msnp2p_cookie();
debug_print("MP: Sending %i bytes: %i-%i of %i\n", msnp2p_binary.size, (int)msnp2p_binary.offset, (int)(msnp2p_binary.offset+msnp2p_binary.size)-1, (int)msnp2p_binary.total_size);
msnp2p_send(session, msnp2p_binary, mpsession->username, picture_data+file_offs, msnp2p_binary.size, 1);
-
+
}
-
+
free(picture_data);
return mpsession;
@@ -582,12 +582,12 @@ static MpSession *msnp2p_incomingsession(SbSession *session, const char *msnslp,
if ( strncmp(msnslp, "INVITE MSNMSGR:", 15) != 0 ) {
return NULL;
}
-
+
content_type = mime_getfield(msnslp, "Content-Type");
if ( strcmp(content_type, "application/x-msnmsgr-transreqbody") == 0 ) {
}
free(content_type);
-
+
session_id_string = mime_getfield_anywhere(msnslp, "SessionID:");
if ( strlen(session_id_string) == 0 ) {
debug_print("MP: Couldn't find SessionID field.\n");
@@ -599,14 +599,14 @@ static MpSession *msnp2p_incomingsession(SbSession *session, const char *msnslp,
/* Return if this packet isn't to be dealt with here. */
if ( session_id == 0 ) {
return NULL;
- }
-
+ }
+
euf_guid = mime_getfield_anywhere(msnslp, "EUF-GUID:");
if ( strlen(euf_guid) == 0 ) {
debug_print("MP: Couldn't find EUF-GUID field.\n");
return NULL;
}
-
+
mpsession = msnp2p_new();
if ( mpsession == NULL ) {
debug_print("MP: Not enough memory to start MSNP2P transfer.\n");
@@ -631,7 +631,7 @@ static MpSession *msnp2p_incomingsession(SbSession *session, const char *msnslp,
mpsession->direction = MSNP2P_DIR_SEND;
mpsession->save_filename = NULL;
mpsession->sha1d = NULL;
-
+
/* Get actual username. */
temp_name = mime_getfield(msnslp, "From:");
if ( temp_name == NULL ) {
@@ -650,9 +650,9 @@ static MpSession *msnp2p_incomingsession(SbSession *session, const char *msnslp,
debug_print("MP: Couldn't find From field.\n");
free(mpsession);
return NULL;
- }
+ }
mpsession->username[strlen(mpsession->username)-1] = '\0';
-
+
switch ( mpsession->type ) {
case MSNP2P_TYPE_DP : debug_print("MP: Got Display Picture Invite from %s\n", mpsession->username); break;
case MSNP2P_TYPE_FT : debug_print("MP: Got File Transfer Invite from %s\n", mpsession->username); break;
@@ -660,7 +660,7 @@ static MpSession *msnp2p_incomingsession(SbSession *session, const char *msnslp,
}
debug_print("MSNSLP: '%s'\n", msnslp);
-
+
acknowledgement.session_id = 0;
acknowledgement.identifier = GINT32_TO_LE(mpsession->baseidentifier);
acknowledgement.offset = 0;
@@ -670,8 +670,8 @@ static MpSession *msnp2p_incomingsession(SbSession *session, const char *msnslp,
acknowledgement.ack_sess = mpheader->identifier;
acknowledgement.ack_id = mpheader->ack_sess;
acknowledgement.ack_size = mpheader->total_size;
- debug_print("MP: Sending BaseIdentifier message\n");
- msnp2p_send(session, acknowledgement, mpsession->username, "", 0, 0);
+ debug_print("MP: Sending BaseIdentifier message\n");
+ msnp2p_send(session, acknowledgement, mpsession->username, "", 0, 0);
if ( mpsession->type == MSNP2P_TYPE_DP ) {
mpsession = msnp2p_send_dp(mpsession, session, msnslp);
@@ -680,7 +680,7 @@ static MpSession *msnp2p_incomingsession(SbSession *session, const char *msnslp,
if ( mpsession != NULL ) {
msnp2p_list = g_list_append(msnp2p_list, mpsession);
}
-
+
return mpsession;
}
@@ -702,7 +702,7 @@ static void msnp2p_sendbye(SbSession *session, MpSession *mpsession) {
strncat(msnslp_block, mpsession->call_id, 38);
strcat(msnslp_block, "\r\nMax-Forwards: 0\r\nContent-Type: application/x-msnmsgr-sessionclosebody\r\nContent-Length: 3");
strcat(msnslp_block, "\r\n\r\n");
-
+
msnslp_length = strlen(msnslp_block);
mpheader.session_id = 0;
@@ -718,17 +718,17 @@ static void msnp2p_sendbye(SbSession *session, MpSession *mpsession) {
debug_print("MP: Sending MSNSLP BYE for display picture.\n");
msnp2p_send(session, mpheader, mpsession->username, msnslp_block, msnslp_length+1, 0);
-
+
free(msnslp_block);
}
static void msnp2p_handledatapacket(SbSession *session, MpHeader *mpheader, MpSession *mpsession, const char *msnslp) {
-
+
FILE *fh;
-
+
debug_print("MP: Got data packet: %i-%i of %i\n", (int)mpheader->offset, (int)(mpheader->offset+mpheader->size)-1, (int)mpheader->total_size);
-
+
fh = fopen(mpsession->save_filename, "a");
if ( fh == NULL ) {
debug_print("MP: Couldn't open avatar file to write data.\n");
@@ -736,13 +736,13 @@ static void msnp2p_handledatapacket(SbSession *session, MpHeader *mpheader, MpSe
}
fwrite(msnslp, 1, mpheader->size, fh);
fclose(fh);
-
+
/* Got all of data? */
if ( mpheader->offset+mpheader->size >= mpheader->total_size ) {
/* Send an acknowledgement for the data */
MpHeader acknowledgement;
-
+
acknowledgement.session_id = mpheader->session_id;
acknowledgement.identifier = GINT32_TO_LE(mpsession->baseidentifier + mpsession->id_increment);
msnp2p_inc(mpsession);
@@ -753,16 +753,16 @@ static void msnp2p_handledatapacket(SbSession *session, MpHeader *mpheader, MpSe
acknowledgement.ack_sess = mpheader->session_id;
acknowledgement.ack_id = mpheader->identifier;
acknowledgement.ack_size = mpheader->total_size;
-
+
msnp2p_send(session, acknowledgement, mpsession->username, "", 0, 0);
-
+
msnp2p_sendbye(session, mpsession);
contactlist_picturekick_sha1d(mpsession->sha1d);
-
+
/* Delay before deletion allows straggling packets to be collected. */
debug_print("MP: Closing MSNP2P session in ten seconds...\n");
mpsession->delete_timeout = g_timeout_add(10000, (GSourceFunc)msnp2p_closesession, mpsession);
-
+
}
}
@@ -775,15 +775,15 @@ static MpSession *msnp2p_check_ink(SbSession *session, const char *username, MpH
if ( !(header->session_id == 64) || !(app_id == 3) ) {
return NULL;
}
-
+
debug_print("MP: Ink packet from '%s'\n", username);
-
+
if ( header->offset == 0 ) {
-
-
+
+
debug_print("MP: First in a sequence of Ink packets.\n");
mpsession = msnp2p_new();
-
+
mpsession->baseidentifier = GINT32_TO_LE(header->identifier);
mpsession->type = MSNP2P_TYPE_INK;
mpsession->direction = MSNP2P_DIR_RECV;
@@ -794,33 +794,33 @@ static MpSession *msnp2p_check_ink(SbSession *session, const char *username, MpH
mpsession->save_filename = NULL;
mpsession->sha1d = NULL;
mpsession->call_id = NULL;
-
+
if ( datalength <= 2000 ) { /* Sanity check */
-
+
mpsession->data = malloc(datalength);
memcpy(mpsession->data, data, datalength);
mpsession->offset = datalength;
-
+
} else {
-
+
debug_print("MP: Ink packet too big - binning.\n");
free(mpsession);
return NULL;
-
+
}
-
+
msnp2p_list = g_list_append(msnp2p_list, mpsession);
-
+
} else {
-
+
mpsession = msnp2p_find_identifier(GINT32_TO_LE(header->identifier));
if ( mpsession == NULL ) {
debug_print("MP: Unrecognised Ink packet.\n");
return NULL;
}
-
+
if ( datalength <= 2000 ) {
-
+
mpsession->data = realloc(mpsession->data, (mpsession->offset) + datalength);
if ( mpsession->data == NULL ) {
debug_print("MP: Whoops! Couldn't allocate memory.\n");
@@ -829,17 +829,17 @@ static MpSession *msnp2p_check_ink(SbSession *session, const char *username, MpH
memcpy((mpsession->data)+(mpsession->offset), data, datalength);
mpsession->offset += datalength;
debug_print("MP: Got some continuing Ink data.\n");
-
+
} else {
debug_print("MP: Ink packet too big - binning.\n");
return NULL;
}
-
-
+
+
}
-
+
assert(mpsession != NULL);
-
+
/* NB It's possible for a single message to be both the first and last in a sequence. */
debug_print("MP: %i of %i bytes.\n", GINT64_TO_LE(header->offset), GINT64_TO_LE(header->total_size));
if ( GINT64_TO_LE(header->offset) >= GINT64_TO_LE(header->total_size) ) {
@@ -850,7 +850,7 @@ static MpSession *msnp2p_check_ink(SbSession *session, const char *username, MpH
GError *error;
debug_print("MP: Last in a sequence of Ink packets.\n");
-
+
debug_print("MP: Decoding UTF-16: %i bytes in.\n", mpsession->offset);
body = g_utf16_to_utf8(mpsession->data, mpsession->offset, &items_in, &new_length, &error);
debug_print("MP: %i items in, %i items out.\n", items_in, new_length);
@@ -867,10 +867,10 @@ static MpSession *msnp2p_check_ink(SbSession *session, const char *username, MpH
debug_print("MP: Ink (%i bytes): '%s'\n", new_length, body);
g_free(body);
}
-
+
debug_print("MP: Closing MSNP2P session in ten seconds...\n");
mpsession->delete_timeout = g_timeout_add(10000, (GSourceFunc)msnp2p_closesession, mpsession);
-
+
}
return mpsession;
@@ -911,7 +911,7 @@ void msnp2p_parsemsg(SbSession *session, const char *username, const char *whole
return;
}
app_id = ntohl(*(int *)(msg+(mpheader->size)+48));
-
+
#ifdef MSNP2P_DEBUG
debug_print("MP: ---- MSNP2P packet ----\n");
debug_print("MP: sessionid = 0x%lx\n", mpheader->session_id);
@@ -947,9 +947,9 @@ void msnp2p_parsemsg(SbSession *session, const char *username, const char *whole
if ( mpsession == NULL ) {
mpsession = msnp2p_check_ink(session, username, mpheader, msnslp, app_id);
}
-
+
/* Past this point, if the message hasn't been matched to a session then it's unrecognised. */
-
+
if ( mpsession == NULL ) {
debug_print("MP: Unrecognised MSNP2P ");
if ( (GINT32_TO_LE(mpheader->flags) & 2) != 0 ) {
@@ -961,17 +961,17 @@ void msnp2p_parsemsg(SbSession *session, const char *username, const char *whole
}
return;
}
-
+
if ( ( GINT32_TO_LE(mpheader->flags) & 2) != 0 ) {
debug_print("MP: Got ACK.\n");
}
if ( ( (GINT32_TO_LE(mpheader->flags) & 2) == 0) && (mpheader->size == mpheader->total_size) ) {
-
+
/* Message wasn't an ACK, so probably needs an ACK sending */
MpHeader acknowledgement;
-
+
acknowledgement.session_id = GINT32_TO_LE(mpheader->session_id);
acknowledgement.identifier = GINT32_TO_LE(mpsession->baseidentifier + mpsession->id_increment);
/* msnp2p_inc(mpsession); */
@@ -987,10 +987,10 @@ void msnp2p_parsemsg(SbSession *session, const char *username, const char *whole
acknowledgement.ack_sess = mpheader->session_id;
acknowledgement.ack_id = mpheader->identifier;
acknowledgement.ack_size = mpheader->size;
-
+
debug_print("MP: Sending ACK.\n");
- msnp2p_send(session, acknowledgement, mpsession->username, "", 0, 0);
-
+ msnp2p_send(session, acknowledgement, mpsession->username, "", 0, 0);
+
}
if ( (app_id == 1) && (GINT64_TO_LE(mpheader->total_size) != 4) ) {
@@ -1005,9 +1005,9 @@ int msnp2p_retrieving(const char *save_filename) {
GList *result = NULL;
result = g_list_find_custom(msnp2p_list, save_filename, (GCompareFunc)msnp2p_compare_savefilename);
- if ( result != NULL ) {
+ if ( result != NULL ) {
/* At least one session exists. Don't care what it is... */
- return 1;
+ return 1;
}
/* Nothing found. */
@@ -1020,12 +1020,12 @@ void msnp2p_getpicture(SbSession *session, const char *username, const char *dpo
MpSession *mpsession;
MpHeader mpheader;
-
+
char *dpobject_decoded;
char *context;
char *data_hash;
char *filename;
-
+
char *request_details;
int request_details_length;
char *request_details_length_string;
@@ -1034,28 +1034,28 @@ void msnp2p_getpicture(SbSession *session, const char *username, const char *dpo
glob_t glob_result;
struct stat stat_buffer;
struct stat *statbuf;
-
+
debug_print("MP: Beginning download for DP from '%s'\n", username);
assert(username != NULL);
assert(session != NULL);
-
+
if ( dpobject == NULL ) {
debug_print("MP: Attempt to download avatar for user who doesn't have one.\n");
return;
}
-
+
if ( sbsessions_sessionready(session) == 0 ) {
debug_print("MP: Session isn't ready to download picture - not trying.\n");
return;
}
-
+
mpsession = msnp2p_new();
if ( mpsession == NULL ) {
debug_print("MP: Not enough memory to do picture request - giving up.\n");
return;
}
-
+
mpsession->parent = session;
mpsession->baseidentifier = msnp2p_cookie();
mpsession->session_id = msnp2p_cookie();
@@ -1081,12 +1081,12 @@ void msnp2p_getpicture(SbSession *session, const char *username, const char *dpo
glob("~", GLOB_TILDE, NULL, &glob_result);
mpsession->save_filename = malloc(strlen(filename)+strlen("/.tuxmessenger/avatars/")+strlen(glob_result.gl_pathv[0]) + 1);
if ( mpsession->save_filename == NULL ) {
-
+
debug_print("MP: Not enough memory to do picture request - giving up.\n");
free(mpsession->call_id);
free(mpsession);
return;
-
+
}
strcpy(mpsession->save_filename, glob_result.gl_pathv[0]);
strcat(mpsession->save_filename, "/.tuxmessenger/avatars/");
@@ -1095,20 +1095,20 @@ void msnp2p_getpicture(SbSession *session, const char *username, const char *dpo
free(filename);
/* Check to see there isn't already a receive session going on for this user. */
-
+
if ( msnp2p_retrieving(mpsession->save_filename) != 0 ) {
debug_print("MP: A DP receive session is already in progress to '%s' - not starting a new one.\n", mpsession->save_filename);
free(mpsession->call_id);
free(mpsession);
return;
-
+
}
/* Check if we already have this picture or not */
statbuf = &stat_buffer;
if ( stat(mpsession->save_filename, statbuf) != -1 ) {
-
+
/* messagewindow_trypicture should have worked this out before. */
debug_print("MP: Already have this picture: %s\n", mpsession->save_filename);
free(mpsession->save_filename);
@@ -1117,32 +1117,32 @@ void msnp2p_getpicture(SbSession *session, const char *username, const char *dpo
return;
}
-
+
/* Silly preliminaries out of the way. Time to do the request... */
-
+
/* Create the payload for the MSNSLP request */
request_details = malloc( 96 + strlen(context) + 9 );
if ( request_details == NULL ) {
-
+
debug_print("MP: Not enough memory to do picture request - giving up.\n");
free(mpsession->save_filename);
free(mpsession->call_id);
free(mpsession);
return;
-
+
}
strcpy(request_details, "EUF-GUID: {A4268EEC-FEC5-49E5-95C3-F126696BDBF6}\r\nSessionID: ");
/* Check we're not about to screw ourselves over. 8 bytes were allowed
above to fit the sessionid into. */
if ( mpsession->session_id > 99999999 ) {
-
+
debug_print("MP: SessionID is too big - giving up.\n");
free(request_details);
free(mpsession->save_filename);
free(mpsession->call_id);
free(mpsession);
return;
-
+
}
sprintf(request_details+strlen(request_details), "%i", mpsession->session_id);
strcat(request_details, "\r\nAppID: 1\r\nContext: ");
@@ -1150,7 +1150,7 @@ void msnp2p_getpicture(SbSession *session, const char *username, const char *dpo
free(context);
strcat(request_details, "\r\n\r\n");
request_details_length = strlen(request_details);
-
+
request_details_length_string = malloc(5);
assert(request_details_length < 9998); /* Sanity check. */
sprintf(request_details_length_string, "%i", request_details_length+1);
@@ -1172,9 +1172,9 @@ void msnp2p_getpicture(SbSession *session, const char *username, const char *dpo
strcat(msnslp_block, request_details);
free(request_details);
msnslp_length = strlen(msnslp_block);
-
+
debug_print("MP: Sending MSNSLP INVITE for display picture.\n");
-
+
/* Now wrap it up with the MSNP2P rubbish */
mpheader.session_id = 0;
mpheader.identifier = GINT32_TO_LE(mpsession->baseidentifier + mpsession->id_increment);
@@ -1186,12 +1186,12 @@ void msnp2p_getpicture(SbSession *session, const char *username, const char *dpo
mpheader.ack_sess = GINT32_TO_LE(mpsession->session_id);
mpheader.ack_id = 0;
mpheader.ack_size = 0;
-
+
msnp2p_send(session, mpheader, username, msnslp_block, strlen(msnslp_block)+1, 0);
-
+
free(msnslp_block);
-
- mpsession->username = strdup(username);
+
+ mpsession->username = strdup(username);
msnp2p_list = g_list_append(msnp2p_list, mpsession);
}
@@ -1200,17 +1200,17 @@ void msnp2p_getpicture(SbSession *session, const char *username, const char *dpo
void msnp2p_abortall(SbSession *session) {
GList *result;
-
+
result = g_list_find_custom(msnp2p_list, &session, (GCompareFunc)msnp2p_compare_parent);
while ( result != NULL ) {
-
+
MpSession *mpsession;
mpsession = result->data;
msnp2p_closesession(mpsession);
result = g_list_find_custom(msnp2p_list, &session, (GCompareFunc)msnp2p_compare_parent);
-
+
}
}
@@ -1225,17 +1225,17 @@ void msnp2p_offerfile(SbSession *session, const char *username, const char *file
char *request_details_length_string;
char *msnslp_block;
size_t msnslp_length;
-
+
assert(session != NULL);
assert(username != NULL);
assert(filename != NULL);
-
+
mpsession = msnp2p_new();
if ( mpsession == NULL ) {
debug_print("MP: Not enough memory to send file - giving up.\n");
return;
}
-
+
mpsession->parent = session;
mpsession->baseidentifier = msnp2p_cookie();
mpsession->session_id = msnp2p_cookie();
@@ -1243,33 +1243,33 @@ void msnp2p_offerfile(SbSession *session, const char *username, const char *file
mpsession->id_increment = 0;
mpsession->call_id = routines_guid();
mpsession->via = NULL;
-
+
context = strdup("WIBBLE!!!112"); /* File preview data... */
debug_print("MP: Generated: Session ID '%i', BaseIdentifier '%i', Call-ID '%s'.\n", mpsession->session_id, mpsession->baseidentifier, mpsession->call_id);
-
+
/* Create the payload for the MSNSLP request */
request_details = malloc( 96 + strlen(context) + 9 );
if ( request_details == NULL ) {
-
+
debug_print("MP: Not enough memory to do picture request - giving up.\n");
free(mpsession->save_filename);
free(mpsession->call_id);
free(mpsession);
return;
-
+
}
strcpy(request_details, "EUF-GUID: {5D3E02AB-6190-11D3-BBBB-00C04F795683}\r\nSessionID: ");
/* Check we're not about to screw ourselves over. 8 bytes were allowed
above to fit the sessionid into. */
if ( mpsession->session_id > 99999999 ) {
-
+
debug_print("MP: SessionID is too big - giving up.\n");
free(request_details);
free(mpsession->call_id);
free(mpsession);
return;
-
+
}
sprintf(request_details+strlen(request_details), "%i", mpsession->session_id);
strcat(request_details, "\r\nAppID: 1\r\nContext: ");
@@ -1277,7 +1277,7 @@ void msnp2p_offerfile(SbSession *session, const char *username, const char *file
free(context);
strcat(request_details, "\r\n\r\n");
request_details_length = strlen(request_details);
-
+
request_details_length_string = malloc(5);
assert(request_details_length < 9998); /* Sanity check. */
sprintf(request_details_length_string, "%i", request_details_length+1);
@@ -1299,9 +1299,9 @@ void msnp2p_offerfile(SbSession *session, const char *username, const char *file
strcat(msnslp_block, request_details);
free(request_details);
msnslp_length = strlen(msnslp_block);
-
+
debug_print("MP: Sending MSNSLP INVITE for file transfer...\n");
-
+
/* Now wrap it up with the MSNP2P rubbish */
mpheader.session_id = 0;
mpheader.identifier = GINT32_TO_LE(mpsession->baseidentifier + mpsession->id_increment);
@@ -1313,12 +1313,12 @@ void msnp2p_offerfile(SbSession *session, const char *username, const char *file
mpheader.ack_sess = GINT32_TO_LE(mpsession->session_id);
mpheader.ack_id = 0;
mpheader.ack_size = 0;
-
+
msnp2p_send(session, mpheader, username, msnslp_block, strlen(msnslp_block)+1, 0);
-
+
free(msnslp_block);
-
- mpsession->username = strdup(username);
+
+ mpsession->username = strdup(username);
msnp2p_list = g_list_append(msnp2p_list, mpsession);
}