Changeset 2309152
- Timestamp:
- 2010-05-17T00:14:14Z (15 years ago)
- Branches:
- master
- Children:
- 553767c
- Parents:
- ec86b22
- Location:
- protocols/purple
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
protocols/purple/Makefile
rec86b22 r2309152 10 10 11 11 # [SH] Program variables 12 objects = purple.o12 objects = ft.o purple.o 13 13 14 14 CFLAGS += -Wall $(PURPLE_CFLAGS) -
protocols/purple/purple.c
rec86b22 r2309152 37 37 static irc_t *local_irc; 38 38 39 st atic struct im_connection *purple_ic_by_pa( PurpleAccount *pa )39 struct im_connection *purple_ic_by_pa( PurpleAccount *pa ) 40 40 { 41 41 GSList *i; … … 827 827 }; 828 828 829 830 struct prpl_xfer_data 831 { 832 PurpleXfer *xfer; 833 file_transfer_t *ft; 834 gint ready_timer; 835 char *buf; 836 int buf_len; 837 }; 838 839 static file_transfer_t *next_ft; 840 841 /* Glorious hack: We seem to have to remind at least some libpurple plugins 842 that we're ready because this info may get lost if we give it too early. 843 So just do it ten times a second. :-/ */ 844 static gboolean prplcb_xfer_write_request_cb( gpointer data, gint fd, b_input_condition cond ) 845 { 846 struct prpl_xfer_data *px = data; 847 848 purple_xfer_ui_ready( px->xfer ); 849 850 return purple_xfer_get_type( px->xfer ) == PURPLE_XFER_RECEIVE; 851 } 852 853 static gboolean prpl_xfer_write_request( struct file_transfer *ft ) 854 { 855 struct prpl_xfer_data *px = ft->data; 856 px->ready_timer = b_timeout_add( 100, prplcb_xfer_write_request_cb, px ); 857 return TRUE; 858 } 859 860 static gssize prplcb_xfer_write( PurpleXfer *xfer, const guchar *buffer, gssize size ) 861 { 862 struct prpl_xfer_data *px = xfer->ui_data; 863 gboolean st; 864 865 b_event_remove( px->ready_timer ); 866 px->ready_timer = 0; 867 868 st = px->ft->write( px->ft, (char*) buffer, size ); 869 870 if( st && xfer->bytes_remaining == size ) 871 imcb_file_finished( px->ft ); 872 873 return st ? size : 0; 874 } 875 876 static gboolean prpl_xfer_write( struct file_transfer *ft, char *buffer, unsigned int len ) 877 { 878 struct prpl_xfer_data *px = ft->data; 879 880 px->buf = g_memdup( buffer, len ); 881 px->buf_len = len; 882 883 //purple_xfer_ui_ready( px->xfer ); 884 px->ready_timer = b_timeout_add( 0, prplcb_xfer_write_request_cb, px ); 885 886 return TRUE; 887 } 888 889 static void prpl_xfer_accept( struct file_transfer *ft ) 890 { 891 struct prpl_xfer_data *px = ft->data; 892 purple_xfer_request_accepted( px->xfer, NULL ); 893 prpl_xfer_write_request( ft ); 894 } 895 896 static void prpl_xfer_canceled( struct file_transfer *ft, char *reason ) 897 { 898 struct prpl_xfer_data *px = ft->data; 899 purple_xfer_request_denied( px->xfer ); 900 } 901 902 static gboolean prplcb_xfer_new_send_cb( gpointer data, gint fd, b_input_condition cond ) 903 { 904 PurpleXfer *xfer = data; 905 struct im_connection *ic = purple_ic_by_pa( xfer->account ); 906 struct prpl_xfer_data *px = g_new0( struct prpl_xfer_data, 1 ); 907 PurpleBuddy *buddy; 908 const char *who; 909 910 buddy = purple_find_buddy( xfer->account, xfer->who ); 911 who = buddy ? purple_buddy_get_name( buddy ) : xfer->who; 912 913 /* TODO(wilmer): After spreading some more const goodness in BitlBee, 914 remove the evil cast below. */ 915 px->ft = imcb_file_send_start( ic, (char*) who, xfer->filename, xfer->size ); 916 px->ft->data = px; 917 px->xfer = data; 918 px->xfer->ui_data = px; 919 920 px->ft->accept = prpl_xfer_accept; 921 px->ft->canceled = prpl_xfer_canceled; 922 px->ft->write_request = prpl_xfer_write_request; 923 924 return FALSE; 925 } 926 927 static void prplcb_xfer_new( PurpleXfer *xfer ) 928 { 929 if( purple_xfer_get_type( xfer ) == PURPLE_XFER_RECEIVE ) 930 { 931 /* This should suppress the stupid file dialog. */ 932 purple_xfer_set_local_filename( xfer, "/tmp/wtf123" ); 933 934 /* Sadly the xfer struct is still empty ATM so come back after 935 the caller is done. */ 936 b_timeout_add( 0, prplcb_xfer_new_send_cb, xfer ); 937 } 938 else 939 { 940 struct prpl_xfer_data *px = g_new0( struct prpl_xfer_data, 1 ); 941 942 px->ft = next_ft; 943 px->ft->data = px; 944 px->xfer = xfer; 945 px->xfer->ui_data = px; 946 947 purple_xfer_set_filename( xfer, px->ft->file_name ); 948 purple_xfer_set_size( xfer, px->ft->file_size ); 949 950 next_ft = NULL; 951 } 952 } 953 954 static void prplcb_xfer_dbg( PurpleXfer *xfer ) 955 { 956 fprintf( stderr, "prplcb_xfer_dbg 0x%p\n", xfer ); 957 } 958 959 gssize prplcb_xfer_read( PurpleXfer *xfer, guchar **buffer, gssize size ) 960 { 961 struct prpl_xfer_data *px = xfer->ui_data; 962 963 fprintf( stderr, "xfer_read %d %d\n", size, px->buf_len ); 964 965 if( px->buf ) 966 { 967 *buffer = px->buf; 968 px->buf = NULL; 969 970 px->ft->write_request( px->ft ); 971 972 return px->buf_len; 973 } 974 975 return 0; 976 } 977 978 static PurpleXferUiOps bee_xfer_uiops = 979 { 980 prplcb_xfer_new, 981 prplcb_xfer_dbg, 982 prplcb_xfer_dbg, 983 prplcb_xfer_dbg, 984 prplcb_xfer_dbg, 985 prplcb_xfer_dbg, 986 prplcb_xfer_write, 987 prplcb_xfer_read, 988 prplcb_xfer_dbg, 989 }; 990 991 static gboolean prplcb_xfer_send_cb( gpointer data, gint fd, b_input_condition cond ); 992 993 void purple_transfer_request( struct im_connection *ic, file_transfer_t *ft, char *handle ) 994 { 995 PurpleAccount *pa = ic->proto_data; 996 struct prpl_xfer_data *px; 997 998 /* xfer_new() will pick up this variable. It's a hack but we're not 999 multi-threaded anyway. */ 1000 next_ft = ft; 1001 serv_send_file( purple_account_get_connection( pa ), handle, ft->file_name ); 1002 1003 ft->write = prpl_xfer_write; 1004 1005 px = ft->data; 1006 imcb_file_recv_start( ft ); 1007 1008 px->ready_timer = b_timeout_add( 100, prplcb_xfer_send_cb, px ); 1009 } 1010 1011 static gboolean prplcb_xfer_send_cb( gpointer data, gint fd, b_input_condition cond ) 1012 { 1013 struct prpl_xfer_data *px = data; 1014 1015 if( px->ft->status & FT_STATUS_TRANSFERRING ) 1016 { 1017 fprintf( stderr, "The ft, it is ready...\n" ); 1018 px->ft->write_request( px->ft ); 1019 1020 return FALSE; 1021 } 1022 1023 return TRUE; 1024 } 829 extern PurpleXferUiOps bee_xfer_uiops; 1025 830 1026 831 static void purple_ui_init()
Note: See TracChangeset
for help on using the changeset viewer.