comparison libpurple/protocols/mxit/protocol.c @ 29036:06fabb28bc69

The "packed" attribute on the raw_chunk data-structure seems to be a GCC extension. (ie, no alignment padding between members of the structure) To build with compilers which don't support this packed attribute, we've now use methods to access/modify the fields in the packed MXit chunk header.
author andrew.victor@mxit.com
date Tue, 24 Nov 2009 13:23:27 +0000
parents 66c4fbe088d0
children 259bbfb423d4
comparison
equal deleted inserted replaced
29035:86fec8bfe88c 29036:06fabb28bc69
1033 */ 1033 */
1034 void mxit_send_file( struct MXitSession* session, const char* username, const char* filename, const unsigned char* buf, int buflen ) 1034 void mxit_send_file( struct MXitSession* session, const char* username, const char* filename, const unsigned char* buf, int buflen )
1035 { 1035 {
1036 char data[CP_MAX_PACKET]; 1036 char data[CP_MAX_PACKET];
1037 int datalen = 0; 1037 int datalen = 0;
1038 struct raw_chunk* chunk; 1038 gchar* chunk;
1039 int size; 1039 int size;
1040 1040
1041 purple_debug_info( MXIT_PLUGIN_ID, "SENDING FILE '%s' of %i bytes to user '%s'\n", filename, buflen, username ); 1041 purple_debug_info( MXIT_PLUGIN_ID, "SENDING FILE '%s' of %i bytes to user '%s'\n", filename, buflen, username );
1042 1042
1043 /* convert the packet to a byte stream */ 1043 /* convert the packet to a byte stream */
1044 datalen = sprintf( data, "ms=" ); 1044 datalen = sprintf( data, "ms=" );
1045 1045
1046 /* map chunk header over data buffer */ 1046 /* map chunk header over data buffer */
1047 chunk = (struct raw_chunk *) &data[datalen]; 1047 chunk = &data[datalen];
1048 1048
1049 size = mxit_chunk_create_senddirect( chunk->data, username, filename, buf, buflen ); 1049 size = mxit_chunk_create_senddirect( chunk_data( chunk ), username, filename, buf, buflen );
1050 if ( size < 0 ) { 1050 if ( size < 0 ) {
1051 purple_debug_error( MXIT_PLUGIN_ID, "Error creating senddirect chunk (%i)\n", size ); 1051 purple_debug_error( MXIT_PLUGIN_ID, "Error creating senddirect chunk (%i)\n", size );
1052 return; 1052 return;
1053 } 1053 }
1054 1054
1055 chunk->type = CP_CHUNK_DIRECT_SND; 1055 set_chunk_type( chunk, CP_CHUNK_DIRECT_SND );
1056 chunk->length = htonl( size ); 1056 set_chunk_length( chunk, size );
1057 datalen += sizeof( struct raw_chunk ) + size; 1057 datalen += MXIT_CHUNK_HEADER_SIZE + size;
1058 1058
1059 /* send the byte stream to the mxit server */ 1059 /* send the byte stream to the mxit server */
1060 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA ); 1060 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
1061 } 1061 }
1062 1062
1069 */ 1069 */
1070 void mxit_send_file_reject( struct MXitSession* session, const char* fileid ) 1070 void mxit_send_file_reject( struct MXitSession* session, const char* fileid )
1071 { 1071 {
1072 char data[CP_MAX_PACKET]; 1072 char data[CP_MAX_PACKET];
1073 int datalen = 0; 1073 int datalen = 0;
1074 struct raw_chunk* chunk; 1074 gchar* chunk;
1075 int size; 1075 int size;
1076 1076
1077 purple_debug_info( MXIT_PLUGIN_ID, "mxit_send_file_reject\n" ); 1077 purple_debug_info( MXIT_PLUGIN_ID, "mxit_send_file_reject\n" );
1078 1078
1079 /* convert the packet to a byte stream */ 1079 /* convert the packet to a byte stream */
1080 datalen = sprintf( data, "ms=" ); 1080 datalen = sprintf( data, "ms=" );
1081 1081
1082 /* map chunk header over data buffer */ 1082 /* map chunk header over data buffer */
1083 chunk = (struct raw_chunk *) &data[datalen]; 1083 chunk = &data[datalen];
1084 1084
1085 size = mxit_chunk_create_reject( chunk->data, fileid ); 1085 size = mxit_chunk_create_reject( chunk_data( chunk ), fileid );
1086 if ( size < 0 ) { 1086 if ( size < 0 ) {
1087 purple_debug_error( MXIT_PLUGIN_ID, "Error creating reject chunk (%i)\n", size ); 1087 purple_debug_error( MXIT_PLUGIN_ID, "Error creating reject chunk (%i)\n", size );
1088 return; 1088 return;
1089 } 1089 }
1090 1090
1091 chunk->type = CP_CHUNK_REJECT; 1091 set_chunk_type( chunk, CP_CHUNK_REJECT );
1092 chunk->length = htonl( size ); 1092 set_chunk_length( chunk, size );
1093 datalen += sizeof( struct raw_chunk ) + size; 1093 datalen += MXIT_CHUNK_HEADER_SIZE + size;
1094 1094
1095 /* send the byte stream to the mxit server */ 1095 /* send the byte stream to the mxit server */
1096 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA ); 1096 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
1097 } 1097 }
1098 1098
1107 */ 1107 */
1108 void mxit_send_file_accept( struct MXitSession* session, const char* fileid, int filesize, int offset ) 1108 void mxit_send_file_accept( struct MXitSession* session, const char* fileid, int filesize, int offset )
1109 { 1109 {
1110 char data[CP_MAX_PACKET]; 1110 char data[CP_MAX_PACKET];
1111 int datalen = 0; 1111 int datalen = 0;
1112 struct raw_chunk* chunk; 1112 gchar* chunk;
1113 int size; 1113 int size;
1114 1114
1115 purple_debug_info( MXIT_PLUGIN_ID, "mxit_send_file_accept\n" ); 1115 purple_debug_info( MXIT_PLUGIN_ID, "mxit_send_file_accept\n" );
1116 1116
1117 /* convert the packet to a byte stream */ 1117 /* convert the packet to a byte stream */
1118 datalen = sprintf( data, "ms=" ); 1118 datalen = sprintf( data, "ms=" );
1119 1119
1120 /* map chunk header over data buffer */ 1120 /* map chunk header over data buffer */
1121 chunk = (struct raw_chunk *) &data[datalen]; 1121 chunk = &data[datalen];
1122 1122
1123 size = mxit_chunk_create_get( chunk->data, fileid, filesize, offset ); 1123 size = mxit_chunk_create_get( chunk_data(chunk), fileid, filesize, offset );
1124 if ( size < 0 ) { 1124 if ( size < 0 ) {
1125 purple_debug_error( MXIT_PLUGIN_ID, "Error creating getfile chunk (%i)\n", size ); 1125 purple_debug_error( MXIT_PLUGIN_ID, "Error creating getfile chunk (%i)\n", size );
1126 return; 1126 return;
1127 } 1127 }
1128 1128
1129 chunk->type = CP_CHUNK_GET; 1129 set_chunk_type( chunk, CP_CHUNK_GET );
1130 chunk->length = htonl( size ); 1130 set_chunk_length( chunk, size );
1131 datalen += sizeof( struct raw_chunk ) + size; 1131 datalen += MXIT_CHUNK_HEADER_SIZE + size;
1132 1132
1133 /* send the byte stream to the mxit server */ 1133 /* send the byte stream to the mxit server */
1134 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA ); 1134 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
1135 } 1135 }
1136 1136
1143 */ 1143 */
1144 void mxit_send_file_received( struct MXitSession* session, const char* fileid, short status ) 1144 void mxit_send_file_received( struct MXitSession* session, const char* fileid, short status )
1145 { 1145 {
1146 char data[CP_MAX_PACKET]; 1146 char data[CP_MAX_PACKET];
1147 int datalen = 0; 1147 int datalen = 0;
1148 struct raw_chunk* chunk; 1148 gchar* chunk;
1149 int size; 1149 int size;
1150 1150
1151 purple_debug_info( MXIT_PLUGIN_ID, "mxit_send_file_received\n" ); 1151 purple_debug_info( MXIT_PLUGIN_ID, "mxit_send_file_received\n" );
1152 1152
1153 /* convert the packet to a byte stream */ 1153 /* convert the packet to a byte stream */
1154 datalen = sprintf( data, "ms=" ); 1154 datalen = sprintf( data, "ms=" );
1155 1155
1156 /* map chunk header over data buffer */ 1156 /* map chunk header over data buffer */
1157 chunk = (struct raw_chunk *) &data[datalen]; 1157 chunk = &data[datalen];
1158 1158
1159 size = mxit_chunk_create_received( chunk->data, fileid, status ); 1159 size = mxit_chunk_create_received( chunk_data(chunk), fileid, status );
1160 if ( size < 0 ) { 1160 if ( size < 0 ) {
1161 purple_debug_error( MXIT_PLUGIN_ID, "Error creating received chunk (%i)\n", size ); 1161 purple_debug_error( MXIT_PLUGIN_ID, "Error creating received chunk (%i)\n", size );
1162 return; 1162 return;
1163 } 1163 }
1164 1164
1165 chunk->type = CP_CHUNK_RECIEVED; 1165 set_chunk_type( chunk, CP_CHUNK_RECIEVED );
1166 chunk->length = htonl( size ); 1166 set_chunk_length( chunk, size );
1167 datalen += sizeof( struct raw_chunk ) + size; 1167 datalen += MXIT_CHUNK_HEADER_SIZE + size;
1168 1168
1169 /* send the byte stream to the mxit server */ 1169 /* send the byte stream to the mxit server */
1170 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA ); 1170 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
1171 } 1171 }
1172 1172
1180 */ 1180 */
1181 void mxit_set_avatar( struct MXitSession* session, const unsigned char* avatar, int avatarlen ) 1181 void mxit_set_avatar( struct MXitSession* session, const unsigned char* avatar, int avatarlen )
1182 { 1182 {
1183 char data[CP_MAX_PACKET]; 1183 char data[CP_MAX_PACKET];
1184 int datalen = 0; 1184 int datalen = 0;
1185 struct raw_chunk* chunk; 1185 gchar* chunk;
1186 int size; 1186 int size;
1187 1187
1188 purple_debug_info( MXIT_PLUGIN_ID, "mxit_set_avatar: %i bytes\n", avatarlen ); 1188 purple_debug_info( MXIT_PLUGIN_ID, "mxit_set_avatar: %i bytes\n", avatarlen );
1189 1189
1190 /* convert the packet to a byte stream */ 1190 /* convert the packet to a byte stream */
1191 datalen = sprintf( data, "ms=" ); 1191 datalen = sprintf( data, "ms=" );
1192 1192
1193 /* map chunk header over data buffer */ 1193 /* map chunk header over data buffer */
1194 chunk = (struct raw_chunk *) &data[datalen]; 1194 chunk = &data[datalen];
1195 1195
1196 size = mxit_chunk_create_set_avatar( chunk->data, avatar, avatarlen ); 1196 size = mxit_chunk_create_set_avatar( chunk_data(chunk), avatar, avatarlen );
1197 if ( size < 0 ) { 1197 if ( size < 0 ) {
1198 purple_debug_error( MXIT_PLUGIN_ID, "Error creating set avatar chunk (%i)\n", size ); 1198 purple_debug_error( MXIT_PLUGIN_ID, "Error creating set avatar chunk (%i)\n", size );
1199 return; 1199 return;
1200 } 1200 }
1201 1201
1202 chunk->type = CP_CHUNK_SET_AVATAR; 1202 set_chunk_type( chunk, CP_CHUNK_SET_AVATAR );
1203 chunk->length = htonl( size ); 1203 set_chunk_length( chunk, size );
1204 datalen += sizeof( struct raw_chunk ) + size; 1204 datalen += MXIT_CHUNK_HEADER_SIZE + size;
1205 1205
1206 /* send the byte stream to the mxit server */ 1206 /* send the byte stream to the mxit server */
1207 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA ); 1207 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
1208 } 1208 }
1209 1209
1219 */ 1219 */
1220 void mxit_get_avatar( struct MXitSession* session, const char* mxitId, const char* avatarId ) 1220 void mxit_get_avatar( struct MXitSession* session, const char* mxitId, const char* avatarId )
1221 { 1221 {
1222 char data[CP_MAX_PACKET]; 1222 char data[CP_MAX_PACKET];
1223 int datalen = 0; 1223 int datalen = 0;
1224 struct raw_chunk* chunk; 1224 gchar* chunk;
1225 int size; 1225 int size;
1226 1226
1227 purple_debug_info( MXIT_PLUGIN_ID, "mxit_get_avatar: %s\n", mxitId ); 1227 purple_debug_info( MXIT_PLUGIN_ID, "mxit_get_avatar: %s\n", mxitId );
1228 1228
1229 /* convert the packet to a byte stream */ 1229 /* convert the packet to a byte stream */
1230 datalen = sprintf( data, "ms=" ); 1230 datalen = sprintf( data, "ms=" );
1231 1231
1232 /* map chunk header over data buffer */ 1232 /* map chunk header over data buffer */
1233 chunk = (struct raw_chunk *) &data[datalen]; 1233 chunk = &data[datalen];
1234 1234
1235 size = mxit_chunk_create_get_avatar( chunk->data, mxitId, avatarId, MXIT_AVATAR_SIZE ); 1235 size = mxit_chunk_create_get_avatar( chunk_data(chunk), mxitId, avatarId, MXIT_AVATAR_SIZE );
1236 if ( size < 0 ) { 1236 if ( size < 0 ) {
1237 purple_debug_error( MXIT_PLUGIN_ID, "Error creating get avatar chunk (%i)\n", size ); 1237 purple_debug_error( MXIT_PLUGIN_ID, "Error creating get avatar chunk (%i)\n", size );
1238 return; 1238 return;
1239 } 1239 }
1240 1240
1241 chunk->type = CP_CHUNK_GET_AVATAR; 1241 set_chunk_type( chunk, CP_CHUNK_GET_AVATAR );
1242 chunk->length = htonl( size ); 1242 set_chunk_length( chunk, size );
1243 datalen += sizeof( struct raw_chunk ) + size; 1243 datalen += MXIT_CHUNK_HEADER_SIZE + size;
1244 1244
1245 /* send the byte stream to the mxit server */ 1245 /* send the byte stream to the mxit server */
1246 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA ); 1246 mxit_queue_packet( session, data, datalen, CP_CMD_MEDIA );
1247 } 1247 }
1248 1248