/* Receive a message on the TCP layer */ STREAM tcp_recv(int length) { int rcvd = 0; if (length > in.size) { in.data = xrealloc(in.data, length); in.size = length; } in.end = in.p = in.data; while (length > 0) { if (!ui_select(sock)) /* User quit */ return NULL; rcvd = recv(sock, in.end, length, 0); if (rcvd == -1) { error("recv: %s\n", strerror(errno)); return NULL; } in.end += rcvd; length -= rcvd; } return ∈ }
/* Receive a message on the TCP layer */ STREAM tcp_recv(STREAM s, uint32 length) { unsigned int new_length, end_offset, p_offset; int rcvd = 0; if (s == NULL) { /* read into "new" stream */ if (length > in.size) { in.data = (uint8 *) xrealloc(in.data, length); in.size = length; } in.end = in.p = in.data; s = ∈ } else { /* append to existing stream */ new_length = (s->end - s->data) + length; if (new_length > s->size) { p_offset = s->p - s->data; end_offset = s->end - s->data; s->data = (uint8 *) xrealloc(s->data, new_length); s->size = new_length; s->p = s->data + p_offset; s->end = s->data + end_offset; } } while (length > 0) { if (!ui_select(sock)) /* User quit */ return NULL; rcvd = recv(sock, s->end, length, 0); if (rcvd <= 0) { error("recv: %s\n", strerror(errno)); return NULL; } s->end += rcvd; length -= rcvd; } return s; }
static void ch_dialog(void) { const char *label; const char *value; const char **options; int n, choice; int label_h; label = pdf_field_label(ctx, ch_widget->obj); label_h = ui_break_lines((char*)label, NULL, 20, 394, NULL); n = pdf_choice_widget_options(ctx, ch_widget->page->doc, ch_widget, 0, NULL); options = fz_malloc_array(ctx, n, sizeof(char*)); pdf_choice_widget_options(ctx, ch_widget->page->doc, ch_widget, 0, options); value = pdf_field_value(ctx, ch_widget->obj); ui_dialog_begin(400, (ui.gridsize+4)*3 + ui.lineheight*(label_h-1)); { ui_layout(T, X, NW, 2, 2); ui_label("%s", label); choice = ui_select("Widget/Ch", value, options, n); if (choice >= 0) pdf_set_choice_field_value(ctx, ch_widget, options[choice]); ui_layout(B, X, NW, 2, 2); ui_panel_begin(0, ui.gridsize, 0, 0, 0); { ui_layout(R, NONE, S, 0, 0); if (ui_button("Cancel") || (!ui.focus && ui.key == KEY_ESCAPE)) ui.dialog = NULL; ui_spacer(); if (ui_button("Okay")) { if (pdf_update_page(ctx, ch_widget->page)) render_page(); ui.dialog = NULL; } } ui_panel_end(); } ui_dialog_end(); fz_free(ctx, options); }
/* Read length bytes from tcp socket to stream and return it. * Appends to stream s if specified, otherwise it uses stream from tcp layer. * Will block until data available. * Returns NULL on error. */ STREAM tcp_recv(rdpTcp * tcp, STREAM s, uint32 length) { int rcvd = 0; uint32 p_offset; uint32 new_length; uint32 end_offset; if (s == NULL) { /* read into "new" stream */ if (length > tcp->in.size) { tcp->in.data = (uint8 *) xrealloc(tcp->in.data, length); tcp->in.size = length; } tcp->in.end = tcp->in.p = tcp->in.data; s = &(tcp->in); } else { /* append to existing stream */ new_length = (s->end - s->data) + length; if (new_length > s->size) { p_offset = s->p - s->data; end_offset = s->end - s->data; s->data = (uint8 *) xrealloc(s->data, new_length); s->size = new_length; s->p = s->data + p_offset; s->end = s->data + end_offset; } } while (length > 0) { #ifndef DISABLE_TLS if (tcp->iso->mcs->sec->tls_connected) { rcvd = tls_read(tcp->iso->mcs->sec->ssl, (char*) s->end, length); if (rcvd < 0) return NULL; } else #endif { if (!ui_select(tcp->iso->mcs->sec->rdp->inst, tcp->sock)) return NULL; /* user quit */ rcvd = recv(tcp->sock, s->end, length, 0); if (rcvd < 0) { if (rcvd == -1 && TCP_BLOCKS) { tcp_can_recv(tcp->sock, 1); rcvd = 0; } else { ui_error(tcp->iso->mcs->sec->rdp->inst, "recv: %s\n", TCP_STRERROR); return NULL; } } else if (rcvd == 0) { ui_error(tcp->iso->mcs->sec->rdp->inst, "Connection closed\n"); return NULL; } } s->end += rcvd; length -= rcvd; } return s; }
/* Receive a message on the TCP layer */ STREAM tcp_recv(STREAM s, uint32 length) { uint32 new_length, end_offset, p_offset; int rcvd = 0, ssl_err; if (g_network_error == True) return NULL; if (s == NULL) { /* read into "new" stream */ if (length > g_in.size) { g_in.data = (uint8 *) xrealloc(g_in.data, length); g_in.size = length; } g_in.end = g_in.p = g_in.data; s = &g_in; } else { /* append to existing stream */ new_length = (s->end - s->data) + length; if (new_length > s->size) { p_offset = s->p - s->data; end_offset = s->end - s->data; s->data = (uint8 *) xrealloc(s->data, new_length); s->size = new_length; s->p = s->data + p_offset; s->end = s->data + end_offset; } } while (length > 0) { if ((!g_ssl || SSL_pending(g_ssl) <= 0) && g_run_ui) { if (!ui_select(g_sock)) { /* User quit */ g_user_quit = True; return NULL; } } if (g_ssl) { rcvd = SSL_read(g_ssl, s->end, length); ssl_err = SSL_get_error(g_ssl, rcvd); if (ssl_err == SSL_ERROR_SSL) { if (SSL_get_shutdown(g_ssl) & SSL_RECEIVED_SHUTDOWN) { error("Remote peer initiated ssl shutdown.\n"); return NULL; } ERR_print_errors_fp(stdout); g_network_error = True; return NULL; } if (ssl_err == SSL_ERROR_WANT_READ || ssl_err == SSL_ERROR_WANT_WRITE) { rcvd = 0; } else if (ssl_err != SSL_ERROR_NONE) { error("SSL_read: %d (%s)\n", ssl_err, TCP_STRERROR); g_network_error = True; return NULL; } } else { rcvd = recv(g_sock, s->end, length, 0); if (rcvd < 0) { if (rcvd == -1 && TCP_BLOCKS) { rcvd = 0; } else { error("recv: %s\n", TCP_STRERROR); g_network_error = True; return NULL; } } else if (rcvd == 0) { error("Connection closed\n"); return NULL; } } s->end += rcvd; length -= rcvd; } return s; }
/* Receive a message on the TCP layer */ STREAM tcp_recv(STREAM s, uint32 length) { uint32 new_length, end_offset, p_offset; int rcvd = 0; if (s == NULL) { /* read into "new" stream */ if (length > g_in.size) { g_in.data = (uint8 *) xrealloc(g_in.data, length); g_in.size = length; } g_in.end = g_in.p = g_in.data; s = &g_in; } else { /* append to existing stream */ new_length = (s->end - s->data) + length; if (new_length > s->size) { p_offset = s->p - s->data; end_offset = s->end - s->data; s->data = (uint8 *) xrealloc(s->data, new_length); s->size = new_length; s->p = s->data + p_offset; s->end = s->data + end_offset; } } while (length > 0) { if (!ui_select(g_sock)) { /* User quit */ g_user_quit = True; return NULL; } rcvd = recv(g_sock, s->end, length, 0); if (rcvd < 0) { if (rcvd == -1 && TCP_BLOCKS) { rcvd = 0; } else { error("recv: %s\n", TCP_STRERROR); return NULL; } } else if (rcvd == 0) { error("Connection closed\n"); return NULL; } s->end += rcvd; length -= rcvd; } return s; }