Ticket #31: buddy_image_01.patch
|
File buddy_image_01.patch, 8.1 KB
(added by difro, 4 years ago)
|
|
|
-
diff --git a/src/nateon.c b/src/nateon.c
index 69177be..1c9732a 100644
|
a
|
b
|
|
| 2258 | 2258 | 0, //OPT_PROTO_MAIL_CHECK, |
| 2259 | 2259 | NULL, /* user_splits */ |
| 2260 | 2260 | NULL, /* protocol_options */ |
| 2261 | | NO_BUDDY_ICONS, /* icon_spec */ |
| | 2261 | { "bmp,jpg", 0, 0, 500, 500, 0, PURPLE_ICON_SCALE_SEND}, /* icon_spec */ |
| 2262 | 2262 | nateon_list_icon, /* list_icon */ |
| 2263 | 2263 | NULL, /* list_emblems */ |
| 2264 | 2264 | nateon_status_text, /* status_text */ |
-
diff --git a/src/switchboard.c b/src/switchboard.c
index 3c0ae75..72deab9 100644
|
a
|
b
|
|
| 806 | 806 | |
| 807 | 807 | g_strfreev(split); |
| 808 | 808 | } |
| | 809 | else if (cmd->param_count == 4 && !strcmp(cmd->params[2], "DPIMG") && \ |
| | 810 | !strncmp(cmd->params[3], "REQUEST", strlen("REQUEST")) ) |
| | 811 | { |
| | 812 | /* Receive Buddy Image */ |
| | 813 | char **split; |
| | 814 | char **file_data; |
| | 815 | PurpleBuddyIcon *icon; |
| | 816 | char *icon_checksum; |
| | 817 | |
| | 818 | split = g_strsplit(cmd->params[3], "%09", 0); |
| | 819 | file_data = g_strsplit(split[2], "|", 0); |
| | 820 | |
| | 821 | icon = purple_buddy_icons_find(session->account, account_name); |
| | 822 | if ( (icon == NULL) || \ |
| | 823 | ( strcmp(purple_buddy_icon_get_checksum(icon), file_data[0]) != 0)) |
| | 824 | { |
| | 825 | nateon_xfer_receive_buddyimage(session, swboard, account_name, file_data[0],\ |
| | 826 | atoi(file_data[1]), file_data[2]); |
| | 827 | } |
| | 828 | if (icon) |
| | 829 | purple_buddy_icon_unref(icon); |
| | 830 | |
| | 831 | g_strfreev(split); |
| | 832 | } |
| 809 | 833 | } |
| 810 | 834 | |
| 811 | 835 | //static void |
-
diff --git a/src/xfer.c b/src/xfer.c
index 3bb632b..75c605e 100644
|
a
|
b
|
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | static void |
| | 33 | nateon_xfer_cancel_recv_dummy(PurpleXfer *xfer) |
| | 34 | { |
| | 35 | return; |
| | 36 | } |
| | 37 | |
| | 38 | static void |
| 33 | 39 | nateon_xfer_cancel_recv(PurpleXfer *xfer) |
| 34 | 40 | { |
| 35 | 41 | purple_debug_info("nateon", "%s\n", __FUNCTION__); |
| … |
… |
|
| 351 | 357 | if (wc != r) |
| 352 | 358 | { |
| 353 | 359 | purple_debug_error("nateon", "%s:Unable to write whole buffer.\n"); |
| 354 | | purple_xfer_cancel_remote(nate_xfer->prpl_xfer); |
| | 360 | if (nate_xfer->content_type == NATEON_XFER_CONTENT_FILE) |
| | 361 | { |
| | 362 | purple_xfer_cancel_remote(nate_xfer->prpl_xfer); |
| | 363 | } |
| 355 | 364 | g_free(buffer); |
| 356 | 365 | return; |
| 357 | 366 | } |
| 358 | | purple_xfer_set_bytes_sent(nate_xfer->prpl_xfer, nate_xfer->recv_len); |
| 359 | | purple_xfer_update_progress(nate_xfer->prpl_xfer); |
| | 367 | if (nate_xfer->content_type == NATEON_XFER_CONTENT_FILE) |
| | 368 | { |
| | 369 | purple_xfer_set_bytes_sent(nate_xfer->prpl_xfer, nate_xfer->recv_len); |
| | 370 | purple_xfer_update_progress(nate_xfer->prpl_xfer); |
| | 371 | } |
| 360 | 372 | } |
| 361 | 373 | else if (r < 0) |
| 362 | 374 | { |
| 363 | | purple_xfer_cancel_remote(nate_xfer->prpl_xfer); |
| | 375 | if (nate_xfer->content_type == NATEON_XFER_CONTENT_FILE) |
| | 376 | { |
| | 377 | purple_xfer_cancel_remote(nate_xfer->prpl_xfer); |
| | 378 | } |
| 364 | 379 | |
| 365 | 380 | } |
| 366 | 381 | } |
| … |
… |
|
| 381 | 396 | fclose(nate_xfer->dest_fp); |
| 382 | 397 | nate_xfer->dest_fp = NULL; |
| 383 | 398 | } |
| | 399 | if (nate_xfer->content_type == NATEON_XFER_CONTENT_BUDDYIMG) |
| | 400 | { |
| | 401 | const gchar *filepath; |
| | 402 | guchar *imgbuf; |
| | 403 | gint filesize; |
| | 404 | gint ret; |
| | 405 | FILE *fp; |
| | 406 | |
| | 407 | filesize = purple_xfer_get_size(nate_xfer->prpl_xfer); |
| | 408 | imgbuf = g_malloc(filesize); |
| | 409 | filepath = purple_xfer_get_local_filename(nate_xfer->prpl_xfer); |
| | 410 | fp = fopen(filepath, "rb"); |
| | 411 | if (fp) |
| | 412 | { |
| | 413 | ret = fread(imgbuf, 1, filesize, fp); |
| | 414 | fclose(fp); |
| | 415 | if (ret == filesize) |
| | 416 | { |
| | 417 | purple_buddy_icons_set_for_user(nate_xfer->session->account, |
| | 418 | nate_xfer->who, imgbuf, filesize, |
| | 419 | purple_xfer_get_filename(nate_xfer->prpl_xfer)); |
| | 420 | } |
| | 421 | } |
| | 422 | g_unlink(filepath); |
| | 423 | } |
| 384 | 424 | purple_xfer_end(nate_xfer->prpl_xfer); |
| 385 | 425 | } |
| 386 | 426 | |
| … |
… |
|
| 862 | 902 | |
| 863 | 903 | if (purple_xfer_get_type(xfer) == PURPLE_XFER_RECEIVE) |
| 864 | 904 | { |
| 865 | | nate_xfer->dest_fp = fopen(purple_xfer_get_local_filename(xfer), "wb"); |
| | 905 | if (nate_xfer->content_type == NATEON_XFER_CONTENT_FILE) |
| | 906 | { |
| | 907 | nate_xfer->dest_fp = fopen(purple_xfer_get_local_filename(xfer), "wb"); |
| | 908 | } |
| | 909 | else if (nate_xfer->content_type == NATEON_XFER_CONTENT_BUDDYIMG) |
| | 910 | { |
| | 911 | char *filepath; |
| | 912 | nate_xfer->dest_fp = purple_mkstemp(&filepath, TRUE); |
| | 913 | purple_xfer_set_local_filename(xfer, filepath); |
| | 914 | g_free(filepath); |
| | 915 | } |
| 866 | 916 | |
| 867 | 917 | if (nate_xfer->dest_fp == NULL) { |
| 868 | 918 | purple_debug_info("nateon", "%s: Error Writing File %s\n", __FUNCTION__, |
| … |
… |
|
| 1133 | 1183 | |
| 1134 | 1184 | xfer = nateon_xfer_new(session, PURPLE_XFER_RECEIVE, who); |
| 1135 | 1185 | |
| | 1186 | xfer->content_type = NATEON_XFER_CONTENT_FILE; |
| 1136 | 1187 | xfer->file_cookie = g_strdup(cookie); |
| 1137 | 1188 | xfer->swboard = swboard; |
| 1138 | 1189 | purple_xfer_set_filename(xfer->prpl_xfer, filename); |
| … |
… |
|
| 1154 | 1205 | purple_debug_info("nateon", "%s: who:%s file:%s\n", __FUNCTION__, who, filename); |
| 1155 | 1206 | |
| 1156 | 1207 | xfer = nateon_xfer_new(session, PURPLE_XFER_SEND, who); |
| | 1208 | xfer->content_type = NATEON_XFER_CONTENT_FILE; |
| 1157 | 1209 | purple_xfer_set_init_fnc(xfer->prpl_xfer, nateon_xfer_init); |
| 1158 | 1210 | purple_xfer_set_cancel_recv_fnc(xfer->prpl_xfer, nateon_xfer_cancel_recv); |
| 1159 | 1211 | purple_xfer_set_request_denied_fnc(xfer->prpl_xfer, nateon_xfer_request_denied); |
| … |
… |
|
| 1176 | 1228 | void |
| 1177 | 1229 | nateon_xfer_cancel_transfer(NateonSession *session, const char *who, const char *filename, const char *cookie) |
| 1178 | 1230 | { |
| 1179 | | NateonXfer *xfer = NULL; |
| 1180 | | GList *l; |
| 1181 | | |
| 1182 | | for (l = session->xfers; l; l = l->next) |
| 1183 | | { |
| 1184 | | NateonXfer *tmp; |
| 1185 | | tmp = l->data; |
| 1186 | | if ( !strcmp(tmp->who, who) && \ |
| | 1231 | NateonXfer *xfer = NULL; |
| | 1232 | GList *l; |
| | 1233 | |
| | 1234 | for (l = session->xfers; l; l = l->next) |
| | 1235 | { |
| | 1236 | NateonXfer *tmp; |
| | 1237 | tmp = l->data; |
| | 1238 | if ( !strcmp(tmp->who, who) && \ |
| 1187 | 1239 | ((filename == NULL) || !strcmp(purple_xfer_get_filename(tmp->prpl_xfer), filename)) && \ |
| 1188 | | tmp->file_cookie && !strcmp(tmp->file_cookie, cookie) ) |
| 1189 | | { |
| 1190 | | xfer = tmp; |
| 1191 | | break; |
| 1192 | | } |
| 1193 | | } |
| 1194 | | if (!xfer) |
| 1195 | | { |
| 1196 | | purple_debug_info("nateon", "%s: no matching xfer found for deny request\n", __FUNCTION__); |
| 1197 | | return; |
| 1198 | | } |
| | 1240 | tmp->file_cookie && !strcmp(tmp->file_cookie, cookie) ) |
| | 1241 | { |
| | 1242 | xfer = tmp; |
| | 1243 | break; |
| | 1244 | } |
| | 1245 | } |
| | 1246 | if (!xfer) |
| | 1247 | { |
| | 1248 | purple_debug_info("nateon", "%s: no matching xfer found for deny request\n", __FUNCTION__); |
| | 1249 | return; |
| | 1250 | } |
| 1199 | 1251 | |
| 1200 | 1252 | purple_xfer_cancel_remote(xfer->prpl_xfer); |
| 1201 | 1253 | } |
| | 1254 | |
| | 1255 | void |
| | 1256 | nateon_xfer_receive_buddyimage(NateonSession *session, NateonSwitchBoard *swboard, \ |
| | 1257 | const char *who, const char *uniq_name, const int filesize, const char *cookie) |
| | 1258 | { |
| | 1259 | NateonXfer *xfer; |
| | 1260 | |
| | 1261 | xfer = nateon_xfer_new(session, PURPLE_XFER_RECEIVE, who); |
| | 1262 | |
| | 1263 | xfer->file_cookie = g_strdup(cookie); |
| | 1264 | xfer->swboard = swboard; |
| | 1265 | |
| | 1266 | xfer->content_type = NATEON_XFER_CONTENT_BUDDYIMG; |
| | 1267 | |
| | 1268 | purple_xfer_set_filename(xfer->prpl_xfer, uniq_name); |
| | 1269 | purple_xfer_set_size(xfer->prpl_xfer, filesize); |
| | 1270 | purple_xfer_set_cancel_recv_fnc(xfer->prpl_xfer, nateon_xfer_cancel_recv_dummy); |
| | 1271 | //purple_xfer_set_init_fnc(xfer->prpl_xfer, nateon_xfer_init); |
| | 1272 | //purple_xfer_set_request_denied_fnc(xfer->prpl_xfer, nateon_xfer_request_denied); |
| | 1273 | purple_xfer_set_end_fnc(xfer->prpl_xfer, nateon_xfer_end); |
| | 1274 | |
| | 1275 | nateon_xfer_init(xfer->prpl_xfer); |
| | 1276 | } |
-
diff --git a/src/xfer.h b/src/xfer.h
index 8aabdba..4a19c59 100644
|
a
|
b
|
|
| 57 | 57 | NATEON_XFER_CONN_FR |
| 58 | 58 | } NateonXferConnType; |
| 59 | 59 | |
| | 60 | typedef enum |
| | 61 | { |
| | 62 | NATEON_XFER_CONTENT_FILE, |
| | 63 | NATEON_XFER_CONTENT_BUDDYIMG |
| | 64 | } NateonXferContentType; |
| | 65 | |
| 60 | 66 | /** |
| 61 | 67 | * File Transfer. |
| 62 | 68 | */ |
| … |
… |
|
| 70 | 76 | char *who; /**< peer's account name */ |
| 71 | 77 | char *my_ip; |
| 72 | 78 | |
| | 79 | NateonXferConnType content_type; |
| | 80 | |
| 73 | 81 | /* P2P related */ |
| 74 | 82 | PurpleNetworkListenData *p2p_listen_data; |
| 75 | 83 | PurpleProxyConnectData *p2p_connect_data; |
| … |
… |
|
| 134 | 142 | void nateon_xfer_cancel_transfer(NateonSession *session, const char *who, const char *filename,\ |
| 135 | 143 | const char *cookie); |
| 136 | 144 | |
| | 145 | void nateon_xfer_receive_buddyimage(NateonSession *session, NateonSwitchBoard *swboard, \ |
| | 146 | const char *who, const char *uniq_name, const int filesize, const char *cookie); |
| | 147 | |
| 137 | 148 | #endif /* _NATEON_XFER_H_ */ |
Download in other formats:
|
|