/* Checks if the WA protocol has data to output and schedules a write handler */ void waprpl_check_ssl_output(PurpleConnection * gc) { whatsapp_connection *wconn = purple_connection_get_protocol_data(gc); if (wconn->sslfd >= 0) { int r = waAPI_sslhasoutdata(wconn->waAPI); if (r > 0) { /* Need to watch for output data (if we are not doing it already) */ if (wconn->sslwh == 0) wconn->sslwh = purple_input_add(wconn->sslfd, PURPLE_INPUT_WRITE, waprpl_ssl_output_cb, gc); } else if (r < 0) { waprpl_ssl_cerr_cb(0, 0, gc); /* Finished the connection! */ } else { if (wconn->sslwh != 0) purple_input_remove(wconn->sslwh); wconn->sslwh = 0; } purple_debug_info(WHATSAPP_ID, "Watch for output is %d %d\n", r, errno); /* Update transfer status */ int rid, bytes_sent; if (waAPI_fileuploadprogress(wconn->waAPI, &rid, &bytes_sent)) { GList *xfers = purple_xfers_get_all(); while (xfers) { PurpleXfer *xfer = xfers->data; wa_file_upload *xinfo = (wa_file_upload *) xfer->data; if (xinfo->ref_id == rid) { purple_debug_info(WHATSAPP_ID, "Upload progress %d bytes done\n", bytes_sent); purple_xfer_set_bytes_sent(xfer, bytes_sent); purple_xfer_update_progress(xfer); break; } xfers = g_list_next(xfers); } } } // Check uploads to mark them as done :) waprpl_check_complete_uploads(gc); }
/* Checks if the WA protocol has data to output and schedules a write handler */ static void waprpl_check_output(PurpleConnection * gc) { whatsapp_connection *wconn = purple_connection_get_protocol_data(gc); if (wconn->fd < 0) return; if (waAPI_hasoutdata(wconn->waAPI) > 0) { /* Need to watch for output data (if we are not doing it already) */ if (wconn->wh == 0) wconn->wh = purple_input_add(wconn->fd, PURPLE_INPUT_WRITE, waprpl_output_cb, gc); } else { if (wconn->wh != 0) purple_input_remove(wconn->wh); wconn->wh = 0; } check_ssl_requests(purple_connection_get_account(gc)); waprpl_check_complete_uploads(gc); }