libfreerdp-core: started handling multi-fragment TSG PDUs
authorMarc-André Moreau <marcandre.moreau@gmail.com>
Fri, 9 Nov 2012 10:04:39 +0000 (05:04 -0500)
committerMarc-André Moreau <marcandre.moreau@gmail.com>
Fri, 9 Nov 2012 10:04:39 +0000 (05:04 -0500)
libfreerdp/core/rpc.c
libfreerdp/utils/args.c

index 36c41b7..92e6f87 100644 (file)
@@ -247,6 +247,17 @@ void rpc_pdu_header_print(RPC_PDU_HEADER* header)
        printf("frag_length: %d\n", header->frag_length);
        printf("auth_length: %d\n", header->auth_length);
        printf("call_id: %d\n", header->call_id);
+
+       if (header->ptype == PTYPE_RESPONSE)
+       {
+               rpcconn_response_hdr_t* response;
+
+               response = (rpcconn_response_hdr_t*) header;
+               printf("alloc_hint: %d\n", response->alloc_hint);
+               printf("p_cont_id: %d\n", response->p_cont_id);
+               printf("cancel_count: %d\n", response->cancel_count);
+               printf("reserved: %d\n", response->reserved);
+       }
 }
 
 /**
@@ -953,7 +964,9 @@ int rpc_recv_pdu(rdpRpc* rpc)
 {
        int status;
        int bytesRead = 0;
+       int totalBytesRead = 0;
        RPC_PDU_HEADER* header;
+       RPC_PDU_HEADER fragHeader;
 
        /* read first 20 bytes to get RPC PDU Header */
 
@@ -995,6 +1008,54 @@ int rpc_recv_pdu(rdpRpc* rpc)
                bytesRead += status;
        }
 
+       if (!(header->pfc_flags & PFC_LAST_FRAG))
+       {
+               totalBytesRead = bytesRead;
+               CopyMemory(&fragHeader, header, sizeof(RPC_PDU_HEADER));
+
+               printf("Fragmented PDU\n");
+
+               while (!(fragHeader.pfc_flags & PFC_LAST_FRAG))
+               {
+                       bytesRead = 0;
+
+                       printf("Reading Fragment Header\n");
+
+                       while (bytesRead < 20)
+                       {
+                               status = tls_read(rpc->tls_out, &((BYTE*) &fragHeader)[bytesRead], 20 - bytesRead);
+
+                               if (status < 0)
+                               {
+                                       printf("rpc_recv_pdu: error reading fragment header\n");
+                                       return status;
+                               }
+
+                               bytesRead += status;
+                       }
+
+                       if (fragHeader.frag_length > rpc->length)
+                       {
+                               rpc->length = header->frag_length;
+                               rpc->buffer = (BYTE*) realloc(rpc->buffer, rpc->length);
+                               header = (RPC_PDU_HEADER*) rpc->buffer;
+                       }
+
+                       while (totalBytesRead < (fragHeader.frag_length - 20))
+                       {
+                               status = tls_read(rpc->tls_out, &rpc->buffer[totalBytesRead], fragHeader.frag_length - totalBytesRead);
+
+                               if (status < 0)
+                               {
+                                       printf("rpc_recv_pdu: error reading fragment\n");
+                                       return status;
+                               }
+
+                               totalBytesRead += status;
+                       }
+               }
+       }
+
        if (header->ptype == PTYPE_RTS) /* RTS PDU */
        {
                printf("rpc_recv_pdu error: Unexpected RTS PDU\n");
index 61dc090..bc19c6c 100644 (file)
@@ -837,7 +837,7 @@ int freerdp_parse_args(rdpSettings* settings, int argc, char** argv,
                                                }
                                                else
                                                {
-                                                       printf("WARNING: unknown device type: %s\n", data->data[0]);
+                                                       printf("WARNING: unknown device type: %s\n", (char*) data->data[0]);
 
                                                        if (strcmp(data->data[0], "disk") == 0)
                                                                printf("Maybe you meant \"drive\" instead of \"disk\"?\n");