libfreerdp-core: remove TS Gateway send queue
authorMarc-André Moreau <marcandre.moreau@gmail.com>
Mon, 2 Feb 2015 01:47:43 +0000 (20:47 -0500)
committerMarc-André Moreau <marcandre.moreau@gmail.com>
Mon, 2 Feb 2015 01:47:43 +0000 (20:47 -0500)
libfreerdp/core/gateway/http.c
libfreerdp/core/gateway/http.h
libfreerdp/core/gateway/ncacn_http.c
libfreerdp/core/gateway/rpc.c
libfreerdp/core/gateway/rpc.h
libfreerdp/core/gateway/rpc_bind.c
libfreerdp/core/gateway/rpc_client.c
libfreerdp/core/gateway/rpc_client.h
libfreerdp/core/gateway/rts.c
libfreerdp/core/gateway/tsg.c

index e205a48..77b7ef9 100644 (file)
 
 HttpContext* http_context_new()
 {
-       return (HttpContext*)calloc(1, sizeof(HttpContext));
+       return (HttpContext*) calloc(1, sizeof(HttpContext));
 }
 
-void http_context_set_method(HttpContext* http_context, char* method)
+BOOL http_context_set_method(HttpContext* context, const char* Method)
 {
-       if (http_context->Method)
-               free(http_context->Method);
+       free(context->Method);
+       context->Method = _strdup(Method);
 
-       http_context->Method = _strdup(method);
-       // TODO: check result
+       if (!context->Method)
+               return FALSE;
+
+       return TRUE;
 }
 
-void http_context_set_uri(HttpContext* http_context, char* uri)
+BOOL http_context_set_uri(HttpContext* context, const char* URI)
 {
-       if (http_context->URI)
-               free(http_context->URI);
+       free(context->URI);
+       context->URI = _strdup(URI);
 
-       http_context->URI = _strdup(uri);
-       // TODO: check result
+       if (!context->URI)
+               return FALSE;
+
+       return TRUE;
 }
 
-void http_context_set_user_agent(HttpContext* http_context, char* user_agent)
+BOOL http_context_set_user_agent(HttpContext* context, const char* UserAgent)
 {
-       if (http_context->UserAgent)
-               free(http_context->UserAgent);
+       free(context->UserAgent);
+       context->UserAgent = _strdup(UserAgent);
 
-       http_context->UserAgent = _strdup(user_agent);
-       // TODO: check result
+       if (!context->UserAgent)
+               return FALSE;
+
+       return TRUE;
 }
 
-void http_context_set_host(HttpContext* http_context, char* host)
+BOOL http_context_set_host(HttpContext* context, const char* Host)
 {
-       if (http_context->Host)
-               free(http_context->Host);
+       free(context->Host);
+       context->Host = _strdup(Host);
+
+       if (!context->Host)
+               return FALSE;
 
-       http_context->Host = _strdup(host);
-       // TODO: check result
+       return TRUE;
 }
 
-void http_context_set_accept(HttpContext* http_context, char* accept)
+BOOL http_context_set_accept(HttpContext* context, const char* Accept)
 {
-       if (http_context->Accept)
-               free(http_context->Accept);
+       free(context->Accept);
+       context->Accept = _strdup(Accept);
+
+       if (!context->Accept)
+               return FALSE;
 
-       http_context->Accept = _strdup(accept);
-       // TODO: check result
+       return TRUE;
 }
 
-void http_context_set_cache_control(HttpContext* http_context, char* cache_control)
+BOOL http_context_set_cache_control(HttpContext* context, const char* CacheControl)
 {
-       if (http_context->CacheControl)
-               free(http_context->CacheControl);
+       free(context->CacheControl);
+       context->CacheControl = _strdup(CacheControl);
+
+       if (!context->CacheControl)
+               return FALSE;
 
-       http_context->CacheControl = _strdup(cache_control);
-       // TODO: check result
+       return TRUE;
 }
 
-void http_context_set_connection(HttpContext* http_context, char* connection)
+BOOL http_context_set_connection(HttpContext* context, const char* Connection)
 {
-       if (http_context->Connection)
-               free(http_context->Connection);
+       free(context->Connection);
+       context->Connection = _strdup(Connection);
+
+       if (!context->Connection)
+               return FALSE;
 
-       http_context->Connection = _strdup(connection);
-       // TODO: check result
+       return TRUE;
 }
 
-void http_context_set_pragma(HttpContext* http_context, char* pragma)
+BOOL http_context_set_pragma(HttpContext* context, const char* Pragma)
 {
-       if (http_context->Pragma)
-               free(http_context->Pragma);
+       free(context->Pragma);
+       context->Pragma = _strdup(Pragma);
+
+       if (!context->Pragma)
+               return FALSE;
 
-       http_context->Pragma = _strdup(pragma);
-       // TODO: check result
+       return TRUE;
 }
 
-void http_context_free(HttpContext* http_context)
+void http_context_free(HttpContext* context)
 {
-       if (http_context != NULL)
+       if (context)
        {
-               free(http_context->UserAgent);
-               free(http_context->Host);
-               free(http_context->URI);
-               free(http_context->Accept);
-               free(http_context->Method);
-               free(http_context->CacheControl);
-               free(http_context->Connection);
-               free(http_context->Pragma);
-               free(http_context);
+               free(context->UserAgent);
+               free(context->Host);
+               free(context->URI);
+               free(context->Accept);
+               free(context->Method);
+               free(context->CacheControl);
+               free(context->Connection);
+               free(context->Pragma);
+               free(context);
        }
 }
 
-void http_request_set_method(HttpRequest* http_request, char* method)
+BOOL http_request_set_method(HttpRequest* request, const char* Method)
 {
-       if (http_request->Method)
-               free(http_request->Method);
+       free(request->Method);
+       request->Method = _strdup(Method);
+
+       if (!request->Method)
+               return FALSE;
 
-       http_request->Method = _strdup(method);
-       // TODO: check result
+       return TRUE;
 }
 
-void http_request_set_uri(HttpRequest* http_request, char* uri)
+BOOL http_request_set_uri(HttpRequest* request, const char* URI)
 {
-       if (http_request->URI)
-               free(http_request->URI);
+       free(request->URI);
+       request->URI = _strdup(URI);
 
-       http_request->URI = _strdup(uri);
-       // TODO: check result
+       if (!request->URI)
+               return FALSE;
+
+       return TRUE;
 }
 
-void http_request_set_auth_scheme(HttpRequest* http_request, char* auth_scheme)
+BOOL http_request_set_auth_scheme(HttpRequest* request, const char* AuthScheme)
 {
-       if (http_request->AuthScheme)
-               free(http_request->AuthScheme);
+       free(request->AuthScheme);
+       request->AuthScheme = _strdup(AuthScheme);
 
-       http_request->AuthScheme = _strdup(auth_scheme);
-       // TODO: check result
+       if (!request->AuthScheme)
+               return FALSE;
+
+       return TRUE;
 }
 
-void http_request_set_auth_param(HttpRequest* http_request, char* auth_param)
+BOOL http_request_set_auth_param(HttpRequest* request, const char* AuthParam)
 {
-       if (http_request->AuthParam)
-               free(http_request->AuthParam);
+       free(request->AuthParam);
+       request->AuthParam = _strdup(AuthParam);
 
-       http_request->AuthParam = _strdup(auth_param);
-       // TODO: check result
+       if (!request->AuthParam)
+               return FALSE;
+
+       return TRUE;
 }
 
 char* http_encode_body_line(char* param, char* value)
 {
        char* line;
        int length;
+
        length = strlen(param) + strlen(value) + 2;
        line = (char*) malloc(length + 1);
 
@@ -182,9 +207,10 @@ char* http_encode_content_length_line(int ContentLength)
        char* line;
        int length;
        char str[32];
+
        _itoa_s(ContentLength, str, sizeof(str), 10);
        length = strlen("Content-Length") + strlen(str) + 2;
-       line = (char*)malloc(length + 1);
+       line = (char*) malloc(length + 1);
 
        if (!line)
                return NULL;
@@ -197,6 +223,7 @@ char* http_encode_header_line(char* Method, char* URI)
 {
        char* line;
        int length;
+
        length = strlen("HTTP/1.1") + strlen(Method) + strlen(URI) + 2;
        line = (char*)malloc(length + 1);
 
@@ -211,6 +238,7 @@ char* http_encode_authorization_line(char* AuthScheme, char* AuthParam)
 {
        char* line;
        int length;
+
        length = strlen("Authorization") + strlen(AuthScheme) + strlen(AuthParam) + 3;
        line = (char*) malloc(length + 1);
 
@@ -221,11 +249,11 @@ char* http_encode_authorization_line(char* AuthScheme, char* AuthParam)
        return line;
 }
 
-wStream* http_request_write(HttpContext* http_context, HttpRequest* http_request)
+wStream* http_request_write(HttpContext* context, HttpRequest* request)
 {
+       wStream* s;
        int i, count;
        char** lines;
-       wStream* s;
        int length = 0;
 
        count = 0;
@@ -234,14 +262,14 @@ wStream* http_request_write(HttpContext* http_context, HttpRequest* http_request
        if (!lines)
                return NULL;
 
-       lines[count++] = http_encode_header_line(http_request->Method, http_request->URI);
-       lines[count++] = http_encode_body_line("Cache-Control", http_context->CacheControl);
-       lines[count++] = http_encode_body_line("Connection", http_context->Connection);
-       lines[count++] = http_encode_body_line("Pragma", http_context->Pragma);
-       lines[count++] = http_encode_body_line("Accept", http_context->Accept);
-       lines[count++] = http_encode_body_line("User-Agent", http_context->UserAgent);
-       lines[count++] = http_encode_content_length_line(http_request->ContentLength);
-       lines[count++] = http_encode_body_line("Host", http_context->Host);
+       lines[count++] = http_encode_header_line(request->Method, request->URI);
+       lines[count++] = http_encode_body_line("Cache-Control", context->CacheControl);
+       lines[count++] = http_encode_body_line("Connection", context->Connection);
+       lines[count++] = http_encode_body_line("Pragma", context->Pragma);
+       lines[count++] = http_encode_body_line("Accept", context->Accept);
+       lines[count++] = http_encode_body_line("User-Agent", context->UserAgent);
+       lines[count++] = http_encode_content_length_line(request->ContentLength);
+       lines[count++] = http_encode_body_line("Host", context->Host);
 
        /* check that everything went well */
        for (i = 0; i < count; i++)
@@ -250,18 +278,18 @@ wStream* http_request_write(HttpContext* http_context, HttpRequest* http_request
                        goto out_free;
        }
 
-       if (http_request->Authorization)
+       if (request->Authorization)
        {
-               lines[count] = http_encode_body_line("Authorization", http_request->Authorization);
+               lines[count] = http_encode_body_line("Authorization", request->Authorization);
 
                if (!lines[count])
                        goto out_free;
 
                count++;
        }
-       else if (http_request->AuthScheme && http_request->AuthParam)
+       else if (request->AuthScheme && request->AuthParam)
        {
-               lines[count] = http_encode_authorization_line(http_request->AuthScheme, http_request->AuthParam);
+               lines[count] = http_encode_authorization_line(request->AuthScheme, request->AuthParam);
 
                if (!lines[count])
                        goto out_free;
@@ -311,27 +339,27 @@ HttpRequest* http_request_new()
        return (HttpRequest*) calloc(1, sizeof(HttpRequest));
 }
 
-void http_request_free(HttpRequest* http_request)
+void http_request_free(HttpRequest* request)
 {
-       if (!http_request)
+       if (!request)
                return;
 
-       if (http_request->AuthParam)
-               free(http_request->AuthParam);
+       if (request->AuthParam)
+               free(request->AuthParam);
 
-       if (http_request->AuthScheme)
-               free(http_request->AuthScheme);
+       if (request->AuthScheme)
+               free(request->AuthScheme);
 
-       if (http_request->Authorization)
-               free(http_request->Authorization);
+       if (request->Authorization)
+               free(request->Authorization);
 
-       free(http_request->Content);
-       free(http_request->Method);
-       free(http_request->URI);
-       free(http_request);
+       free(request->Content);
+       free(request->Method);
+       free(request->URI);
+       free(request);
 }
 
-BOOL http_response_parse_header_status_line(HttpResponse* http_response, char* status_line)
+BOOL http_response_parse_header_status_line(HttpResponse* response, char* status_line)
 {
        char* separator = NULL;
        char* status_code;
@@ -351,23 +379,23 @@ BOOL http_response_parse_header_status_line(HttpResponse* http_response, char* s
 
        reason_phrase = separator + 1;
        *separator = '\0';
-       http_response->StatusCode = atoi(status_code);
-       http_response->ReasonPhrase = _strdup(reason_phrase);
+       response->StatusCode = atoi(status_code);
+       response->ReasonPhrase = _strdup(reason_phrase);
 
-       if (!http_response->ReasonPhrase)
+       if (!response->ReasonPhrase)
                return FALSE;
 
        *separator = ' ';
        return TRUE;
 }
 
-BOOL http_response_parse_header_field(HttpResponse* http_response, char* name, char* value)
+BOOL http_response_parse_header_field(HttpResponse* response, char* name, char* value)
 {
        BOOL status = TRUE;
 
        if (_stricmp(name, "Content-Length") == 0)
        {
-               http_response->ContentLength = atoi(value);
+               response->ContentLength = atoi(value);
        }
        else if (_stricmp(name, "WWW-Authenticate") == 0)
        {
@@ -404,13 +432,13 @@ BOOL http_response_parse_header_field(HttpResponse* http_response, char* name, c
                        authValue = NULL;
                }
 
-               status = ListDictionary_Add(http_response->Authenticates, authScheme, authValue);
+               status = ListDictionary_Add(response->Authenticates, authScheme, authValue);
        }
 
        return status;
 }
 
-BOOL http_response_parse_header(HttpResponse* http_response)
+BOOL http_response_parse_header(HttpResponse* response)
 {
        int count;
        char* line;
@@ -421,18 +449,18 @@ BOOL http_response_parse_header(HttpResponse* http_response)
        char end_of_header_char;
        char c;
 
-       if (!http_response)
+       if (!response)
                return FALSE;
 
-       if (!http_response->lines)
+       if (!response->lines)
                return FALSE;
 
-       if (!http_response_parse_header_status_line(http_response, http_response->lines[0]))
+       if (!http_response_parse_header_status_line(response, response->lines[0]))
                return FALSE;
 
-       for (count = 1; count < http_response->count; count++)
+       for (count = 1; count < response->count; count++)
        {
-               line = http_response->lines[count];
+               line = response->lines[count];
                /**
                 * name         end_of_header
                 * |            |
@@ -473,7 +501,7 @@ BOOL http_response_parse_header(HttpResponse* http_response)
                                break;
                }
 
-               if (!http_response_parse_header_field(http_response, name, value))
+               if (!http_response_parse_header_field(response, name, value))
                        return FALSE;
 
                *end_of_header = end_of_header_char;
@@ -482,26 +510,25 @@ BOOL http_response_parse_header(HttpResponse* http_response)
        return TRUE;
 }
 
-void http_response_print(HttpResponse* http_response)
+void http_response_print(HttpResponse* response)
 {
        int i;
 
-       for (i = 0; i < http_response->count; i++)
+       for (i = 0; i < response->count; i++)
        {
-               WLog_ERR(TAG, "%s", http_response->lines[i]);
+               WLog_ERR(TAG, "%s", response->lines[i]);
        }
 }
 
 HttpResponse* http_response_recv(rdpTls* tls)
 {
-       BYTE* p;
        int nbytes;
        int length;
        int status;
        BYTE* buffer;
        char* content;
        char* header_end;
-       HttpResponse* http_response;
+       HttpResponse* response;
 
        nbytes = 0;
        length = 10000;
@@ -512,19 +539,18 @@ HttpResponse* http_response_recv(rdpTls* tls)
        if (!buffer)
                return NULL;
 
-       http_response = http_response_new();
+       response = http_response_new();
 
-       if (!http_response)
+       if (!response)
                goto out_free;
 
-       p = buffer;
-       http_response->ContentLength = 0;
+       response->ContentLength = 0;
 
        while (TRUE)
        {
                while (nbytes < 5)
                {
-                       status = BIO_read(tls->bio, p, length - nbytes);
+                       status = BIO_read(tls->bio, &buffer[nbytes], length - nbytes);
 
                        if (status <= 0)
                        {
@@ -539,7 +565,6 @@ HttpResponse* http_response_recv(rdpTls* tls)
                        VALGRIND_MAKE_MEM_DEFINED(p, status);
 #endif
                        nbytes += status;
-                       p = (BYTE*) &buffer[nbytes];
                }
 
                header_end = strstr((char*) buffer, "\r\n\r\n");
@@ -570,43 +595,43 @@ HttpResponse* http_response_recv(rdpTls* tls)
                                count++;
                        }
 
-                       http_response->count = count;
+                       response->count = count;
 
                        if (count)
                        {
-                               http_response->lines = (char**) calloc(http_response->count, sizeof(char*));
+                               response->lines = (char**) calloc(response->count, sizeof(char*));
 
-                               if (!http_response->lines)
+                               if (!response->lines)
                                        goto out_error;
                        }
 
                        count = 0;
                        line = strtok((char*) buffer, "\r\n");
 
-                       while (line && http_response->lines)
+                       while (line && response->lines)
                        {
-                               http_response->lines[count] = _strdup(line);
+                               response->lines[count] = _strdup(line);
 
-                               if (!http_response->lines[count])
+                               if (!response->lines[count])
                                        goto out_error;
 
                                line = strtok(NULL, "\r\n");
                                count++;
                        }
 
-                       if (!http_response_parse_header(http_response))
+                       if (!http_response_parse_header(response))
                                goto out_error;
 
-                       http_response->bodyLen = nbytes - (content - (char*)buffer);
+                       response->BodyLength = nbytes - (content - (char*) buffer);
 
-                       if (http_response->bodyLen > 0)
+                       if (response->BodyLength > 0)
                        {
-                               http_response->BodyContent = (BYTE*) malloc(http_response->bodyLen);
+                               response->BodyContent = (BYTE*) malloc(response->BodyLength);
 
-                               if (!http_response->BodyContent)
+                               if (!response->BodyContent)
                                        goto out_error;
 
-                               CopyMemory(http_response->BodyContent, content, http_response->bodyLen);
+                               CopyMemory(response->BodyContent, content, response->BodyLength);
                        }
 
                        break;
@@ -616,14 +641,13 @@ HttpResponse* http_response_recv(rdpTls* tls)
                {
                        length *= 2;
                        buffer = realloc(buffer, length);
-                       p = (BYTE*) &buffer[nbytes];
                }
        }
 
        free(buffer);
-       return http_response;
+       return response;
 out_error:
-       http_response_free(http_response);
+       http_response_free(response);
 out_free:
        free(buffer);
        return NULL;
@@ -647,42 +671,42 @@ static void string_free(void* obj1)
 
 HttpResponse* http_response_new()
 {
-       HttpResponse* ret = (HttpResponse*) calloc(1, sizeof(HttpResponse));
+       HttpResponse* response = (HttpResponse*) calloc(1, sizeof(HttpResponse));
 
-       if (!ret)
+       if (!response)
                return NULL;
 
-       ret->Authenticates = ListDictionary_New(FALSE);
+       response->Authenticates = ListDictionary_New(FALSE);
 
-       ListDictionary_KeyObject(ret->Authenticates)->fnObjectEquals = strings_equals_nocase;
-       ListDictionary_KeyObject(ret->Authenticates)->fnObjectFree = string_free;
+       ListDictionary_KeyObject(response->Authenticates)->fnObjectEquals = strings_equals_nocase;
+       ListDictionary_KeyObject(response->Authenticates)->fnObjectFree = string_free;
 
-       ListDictionary_ValueObject(ret->Authenticates)->fnObjectEquals = strings_equals_nocase;
-       ListDictionary_ValueObject(ret->Authenticates)->fnObjectFree = string_free;
+       ListDictionary_ValueObject(response->Authenticates)->fnObjectEquals = strings_equals_nocase;
+       ListDictionary_ValueObject(response->Authenticates)->fnObjectFree = string_free;
 
-       return ret;
+       return response;
 }
 
-void http_response_free(HttpResponse* http_response)
+void http_response_free(HttpResponse* response)
 {
        int i;
 
-       if (!http_response)
+       if (!response)
                return;
 
-       for (i = 0; i < http_response->count; i++)
+       for (i = 0; i < response->count; i++)
        {
-               if (http_response->lines && http_response->lines[i])
-                       free(http_response->lines[i]);
+               if (response->lines && response->lines[i])
+                       free(response->lines[i]);
        }
 
-       free(http_response->lines);
-       free(http_response->ReasonPhrase);
+       free(response->lines);
+       free(response->ReasonPhrase);
 
-       ListDictionary_Free(http_response->Authenticates);
+       ListDictionary_Free(response->Authenticates);
 
-       if (http_response->ContentLength > 0)
-               free(http_response->BodyContent);
+       if (response->ContentLength > 0)
+               free(response->BodyContent);
 
-       free(http_response);
+       free(response);
 }
index ded9ba2..375503b 100644 (file)
@@ -41,17 +41,17 @@ struct _http_context
        char* Pragma;
 };
 
-void http_context_set_method(HttpContext* http_context, char* method);
-void http_context_set_uri(HttpContext* http_context, char* uri);
-void http_context_set_user_agent(HttpContext* http_context, char* user_agent);
-void http_context_set_host(HttpContext* http_context, char* host);
-void http_context_set_accept(HttpContext* http_context, char* accept);
-void http_context_set_cache_control(HttpContext* http_context, char* cache_control);
-void http_context_set_connection(HttpContext* http_context, char* connection);
-void http_context_set_pragma(HttpContext* http_context, char* pragma);
+BOOL http_context_set_method(HttpContext* context, const char* Method);
+BOOL http_context_set_uri(HttpContext* context, const char* URI);
+BOOL http_context_set_user_agent(HttpContext* context, const char* UserAgent);
+BOOL http_context_set_host(HttpContext* context, const char* Host);
+BOOL http_context_set_accept(HttpContext* context, const char* Accept);
+BOOL http_context_set_cache_control(HttpContext* context, const char* CacheControl);
+BOOL http_context_set_connection(HttpContext* context, const char* Connection);
+BOOL http_context_set_pragma(HttpContext* context, const char* Pragma);
 
 HttpContext* http_context_new(void);
-void http_context_free(HttpContext* http_context);
+void http_context_free(HttpContext* context);
 
 struct _http_request
 {
@@ -64,15 +64,15 @@ struct _http_request
        char* Content;
 };
 
-void http_request_set_method(HttpRequest* http_request, char* method);
-void http_request_set_uri(HttpRequest* http_request, char* uri);
-void http_request_set_auth_scheme(HttpRequest* http_request, char* auth_scheme);
-void http_request_set_auth_param(HttpRequest* http_request, char* auth_param);
+BOOL http_request_set_method(HttpRequest* request, const char* Method);
+BOOL http_request_set_uri(HttpRequest* request, const char* URI);
+BOOL http_request_set_auth_scheme(HttpRequest* request, const char* AuthScheme);
+BOOL http_request_set_auth_param(HttpRequest* request, const char* AuthParam);
 
-wStream* http_request_write(HttpContext* http_context, HttpRequest* http_request);
+wStream* http_request_write(HttpContext* context, HttpRequest* request);
 
 HttpRequest* http_request_new(void);
-void http_request_free(HttpRequest* http_request);
+void http_request_free(HttpRequest* request);
 
 struct _http_response
 {
@@ -82,17 +82,19 @@ struct _http_response
        int StatusCode;
        char* ReasonPhrase;
 
-       wListDictionary *Authenticates;
        int ContentLength;
-       BYTE *BodyContent;
-       int bodyLen;
+
+       int BodyLength;
+       BYTE* BodyContent;
+
+       wListDictionary* Authenticates;
 };
 
-void http_response_print(HttpResponse* http_response);
+void http_response_print(HttpResponse* response);
 
 HttpResponse* http_response_recv(rdpTls* tls);
 
 HttpResponse* http_response_new(void);
-void http_response_free(HttpResponse* http_response);
+void http_response_free(HttpResponse* response);
 
 #endif /* FREERDP_CORE_HTTP_H */
index 91f9ebd..9d85aa2 100644 (file)
@@ -80,21 +80,26 @@ wStream* rpc_ntlm_http_request(rdpRpc* rpc, SecBuffer* ntlm_token, int content_l
 int rpc_ncacn_http_send_in_channel_request(rdpRpc* rpc)
 {
        wStream* s;
-       int content_length;
-       BOOL continue_needed;
+       int status;
+       int contentLength;
+       BOOL continueNeeded;
        rdpNtlm* ntlm = rpc->NtlmHttpIn->ntlm;
 
-       continue_needed = ntlm_authenticate(ntlm);
+       continueNeeded = ntlm_authenticate(ntlm);
+
+       contentLength = (continueNeeded) ? 0 : 0x40000000;
 
-       content_length = (continue_needed) ? 0 : 0x40000000;
+       s = rpc_ntlm_http_request(rpc, &ntlm->outputBuffer[0], contentLength, TSG_CHANNEL_IN);
 
-       s = rpc_ntlm_http_request(rpc, &ntlm->outputBuffer[0], content_length, TSG_CHANNEL_IN);
+       if (!s)
+               return -1;
 
        WLog_DBG(TAG, "\n%s", Stream_Buffer(s));
-       rpc_in_write(rpc, Stream_Buffer(s), Stream_Length(s));
+
+       status = rpc_in_write(rpc, Stream_Buffer(s), Stream_Length(s));
        Stream_Free(s, TRUE);
 
-       return 0;
+       return (status > 0) ? 1 : -1;
 }
 
 int rpc_ncacn_http_recv_in_channel_response(rdpRpc* rpc)
@@ -125,7 +130,7 @@ out:
        ntlm->inputBuffer[0].cbBuffer = ntlm_token_length;
        http_response_free(http_response);
 
-       return 0;
+       return 1;
 }
 
 int rpc_ncacn_http_ntlm_init(rdpRpc* rpc, TSG_CHANNEL channel)
@@ -164,8 +169,7 @@ int rpc_ncacn_http_ntlm_init(rdpRpc* rpc, TSG_CHANNEL channel)
        }
 
        if (!ntlm_client_init(ntlm, TRUE, settings->GatewayUsername,
-                       settings->GatewayDomain, settings->GatewayPassword,
-                       rpc->TlsIn->Bindings))
+                       settings->GatewayDomain, settings->GatewayPassword, rpc->TlsIn->Bindings))
        {
                return 0;
        }
@@ -180,38 +184,41 @@ int rpc_ncacn_http_ntlm_init(rdpRpc* rpc, TSG_CHANNEL channel)
 
 BOOL rpc_ntlm_http_in_connect(rdpRpc* rpc)
 {
-       BOOL success = FALSE;
+       BOOL status = FALSE;
        rdpNtlm* ntlm = rpc->NtlmHttpIn->ntlm;
 
-       if (rpc_ncacn_http_ntlm_init(rpc, TSG_CHANNEL_IN) == 1)
-       {
-               success = TRUE;
+       if (rpc_ncacn_http_ntlm_init(rpc, TSG_CHANNEL_IN) <= 0)
+               goto out;
 
-               /* Send IN Channel Request */
+       /* Send IN Channel Request */
 
-               rpc_ncacn_http_send_in_channel_request(rpc);
+       if (rpc_ncacn_http_send_in_channel_request(rpc) <= 0)
+               goto out;
 
-               /* Receive IN Channel Response */
+       /* Receive IN Channel Response */
 
-               rpc_ncacn_http_recv_in_channel_response(rpc);
+       if (rpc_ncacn_http_recv_in_channel_response(rpc) <= 0)
+               goto out;
 
-               /* Send IN Channel Request */
+       /* Send IN Channel Request */
 
-               rpc_ncacn_http_send_in_channel_request(rpc);
+       if (rpc_ncacn_http_send_in_channel_request(rpc) <= 0)
+               goto out;
 
-               ntlm_client_uninit(ntlm);
-       }
+       status = TRUE;
 
+out:
+       ntlm_client_uninit(ntlm);
        ntlm_free(ntlm);
-
        rpc->NtlmHttpIn->ntlm = NULL;
 
-       return success;
+       return status;
 }
 
 int rpc_ncacn_http_send_out_channel_request(rdpRpc* rpc)
 {
        wStream* s;
+       int status;
        int content_length;
        BOOL continue_needed;
        rdpNtlm* ntlm = rpc->NtlmHttpOut->ntlm;
@@ -222,11 +229,15 @@ int rpc_ncacn_http_send_out_channel_request(rdpRpc* rpc)
 
        s = rpc_ntlm_http_request(rpc, &ntlm->outputBuffer[0], content_length, TSG_CHANNEL_OUT);
 
+       if (!s)
+               return -1;
+
        WLog_DBG(TAG, "\n%s", Stream_Buffer(s));
-       rpc_out_write(rpc, Stream_Buffer(s), Stream_Length(s));
+
+       status = rpc_out_write(rpc, Stream_Buffer(s), Stream_Length(s));
        Stream_Free(s, TRUE);
 
-       return 0;
+       return (status > 0) ? 1 : -1;
 }
 
 int rpc_ncacn_http_recv_out_channel_response(rdpRpc* rpc)
@@ -245,15 +256,19 @@ int rpc_ncacn_http_recv_out_channel_response(rdpRpc* rpc)
        if (ListDictionary_Contains(http_response->Authenticates, "NTLM"))
        {
                token64 = ListDictionary_GetItemValue(http_response->Authenticates, "NTLM");
+
+               if (!token64)
+                       goto out;
+
                crypto_base64_decode(token64, strlen(token64), &ntlm_token_data, &ntlm_token_length);
        }
 
+out:
        ntlm->inputBuffer[0].pvBuffer = ntlm_token_data;
        ntlm->inputBuffer[0].cbBuffer = ntlm_token_length;
-       
        http_response_free(http_response);
 
-       return 0;
+       return 1;
 }
 
 int rpc_http_send_replacement_out_channel_request(rdpRpc* rpc)
@@ -274,30 +289,32 @@ int rpc_http_send_replacement_out_channel_request(rdpRpc* rpc)
 
 BOOL rpc_ntlm_http_out_connect(rdpRpc* rpc)
 {
+       BOOL status = FALSE;
        rdpNtlm* ntlm = rpc->NtlmHttpOut->ntlm;
-       BOOL success = FALSE;
 
-       if (rpc_ncacn_http_ntlm_init(rpc, TSG_CHANNEL_OUT) == 1)
-       {
-               success = TRUE;
+       if (rpc_ncacn_http_ntlm_init(rpc, TSG_CHANNEL_OUT) <= 0)
+               goto out;
 
-               /* Send OUT Channel Request */
-               rpc_ncacn_http_send_out_channel_request(rpc);
+       /* Send OUT Channel Request */
+       if (rpc_ncacn_http_send_out_channel_request(rpc) <= 0)
+               goto out;
 
-               /* Receive OUT Channel Response */
-               rpc_ncacn_http_recv_out_channel_response(rpc);
+       /* Receive OUT Channel Response */
+       if (rpc_ncacn_http_recv_out_channel_response(rpc) <= 0)
+               goto out;
 
-               /* Send OUT Channel Request */
-               rpc_ncacn_http_send_out_channel_request(rpc);
+       /* Send OUT Channel Request */
+       if (rpc_ncacn_http_send_out_channel_request(rpc) <= 0)
+               goto out;
 
-               ntlm_client_uninit(ntlm);
-       }
+       status = TRUE;
 
+out:
+       ntlm_client_uninit(ntlm);
        ntlm_free(ntlm);
-
        rpc->NtlmHttpOut->ntlm = NULL;
 
-       return success;
+       return status;
 }
 
 void rpc_ntlm_http_init_channel(rdpRpc* rpc, rdpNtlmHttp* ntlm_http, TSG_CHANNEL channel)
index baf915d..8a88184 100644 (file)
@@ -350,16 +350,15 @@ int rpc_in_write(rdpRpc* rpc, const BYTE* data, int length)
 
 int rpc_write(rdpRpc* rpc, BYTE* data, int length, UINT16 opnum)
 {
-       BYTE* buffer = NULL;
        UINT32 offset;
-       rdpNtlm* ntlm;
+       BYTE* buffer = NULL;
        UINT32 stub_data_pad;
        SecBuffer Buffers[2];
        SecBufferDesc Message;
        RpcClientCall* clientCall;
        SECURITY_STATUS encrypt_status;
        rpcconn_request_hdr_t* request_pdu = NULL;
-       ntlm = rpc->ntlm;
+       rdpNtlm* ntlm = rpc->ntlm;
 
        if (!ntlm || !ntlm->table)
        {
@@ -411,6 +410,7 @@ int rpc_write(rdpRpc* rpc, BYTE* data, int length, UINT16 opnum)
        request_pdu->auth_verifier.auth_context_id = 0x00000000;
        offset += (8 + request_pdu->auth_length);
        request_pdu->frag_length = offset;
+
        buffer = (BYTE*) calloc(1, request_pdu->frag_length);
 
        if (!buffer)
@@ -432,9 +432,7 @@ int rpc_write(rdpRpc* rpc, BYTE* data, int length, UINT16 opnum)
        Buffers[1].pvBuffer = calloc(1, Buffers[1].cbBuffer);
 
        if (!Buffers[1].pvBuffer)
-       {
                goto out_free_pdu;
-       }
 
        Message.cBuffers = 2;
        Message.ulVersion = SECBUFFER_VERSION;
@@ -451,7 +449,7 @@ int rpc_write(rdpRpc* rpc, BYTE* data, int length, UINT16 opnum)
        offset += Buffers[1].cbBuffer;
        free(Buffers[1].pvBuffer);
 
-       if (rpc_send_enqueue_pdu(rpc, buffer, request_pdu->frag_length) < 0)
+       if (rpc_send_pdu(rpc, buffer, request_pdu->frag_length) < 0)
                length = -1;
 
        free(request_pdu);
@@ -460,8 +458,8 @@ int rpc_write(rdpRpc* rpc, BYTE* data, int length, UINT16 opnum)
 out_free_clientCall:
        rpc_client_call_free(clientCall);
 out_free_pdu:
-       free (buffer);
-       free (Buffers[1].pvBuffer);
+       free(buffer);
+       free(Buffers[1].pvBuffer);
        free(request_pdu);
        return -1;
 }
@@ -469,6 +467,77 @@ out_free_pdu:
 int rpc_check(rdpRpc* rpc)
 {
        RPC_PDU* pdu;
+       rpcconn_rts_hdr_t* rts;
+
+       if (rpc->State < RPC_CLIENT_STATE_ESTABLISHED)
+       {
+               switch (rpc->VirtualConnection->State)
+               {
+                       case VIRTUAL_CONNECTION_STATE_INITIAL:
+                               break;
+
+                       case VIRTUAL_CONNECTION_STATE_OUT_CHANNEL_WAIT:
+                               break;
+
+                       case VIRTUAL_CONNECTION_STATE_WAIT_A3W:
+
+                               pdu = rpc_recv_dequeue_pdu(rpc, TRUE);
+
+                               if (!pdu)
+                                       return -1;
+
+                               rts = (rpcconn_rts_hdr_t*) Stream_Buffer(pdu->s);
+
+                               if (!rts_match_pdu_signature(rpc, &RTS_PDU_CONN_A3_SIGNATURE, rts))
+                               {
+                                       WLog_ERR(TAG, "unexpected RTS PDU: Expected CONN/A3");
+                                       return -1;
+                               }
+
+                               rts_recv_CONN_A3_pdu(rpc, Stream_Buffer(pdu->s), Stream_Length(pdu->s));
+
+                               rpc_client_receive_pool_return(rpc, pdu);
+
+                               rpc->VirtualConnection->State = VIRTUAL_CONNECTION_STATE_WAIT_C2;
+                               WLog_DBG(TAG, "VIRTUAL_CONNECTION_STATE_WAIT_C2");
+
+                               break;
+
+                       case VIRTUAL_CONNECTION_STATE_WAIT_C2:
+
+                               pdu = rpc_recv_dequeue_pdu(rpc, TRUE);
+
+                               if (!pdu)
+                                       return FALSE;
+
+                               rts = (rpcconn_rts_hdr_t*) Stream_Buffer(pdu->s);
+
+                               if (!rts_match_pdu_signature(rpc, &RTS_PDU_CONN_C2_SIGNATURE, rts))
+                               {
+                                       WLog_ERR(TAG, "unexpected RTS PDU: Expected CONN/C2");
+                                       return FALSE;
+                               }
+
+                               rts_recv_CONN_C2_pdu(rpc, Stream_Buffer(pdu->s), Stream_Length(pdu->s));
+
+                               rpc_client_receive_pool_return(rpc, pdu);
+
+                               rpc->VirtualConnection->State = VIRTUAL_CONNECTION_STATE_OPENED;
+                               WLog_DBG(TAG, "VIRTUAL_CONNECTION_STATE_OPENED");
+
+                               rpc->State = RPC_CLIENT_STATE_ESTABLISHED;
+
+                               break;
+
+                       case VIRTUAL_CONNECTION_STATE_OPENED:
+                               break;
+
+                       case VIRTUAL_CONNECTION_STATE_FINAL:
+                               break;
+               }
+
+               return 1;
+       }
 
        if (rpc->State == RPC_CLIENT_STATE_ESTABLISHED)
        {
@@ -526,6 +595,8 @@ int rpc_connect(rdpRpc* rpc)
                return -1;
        }
 
+       rpc_client_start(rpc);
+
        while (rpc->State != RPC_CLIENT_STATE_CONTEXT_NEGOTIATED)
        {
                if (rpc_check(rpc) < 0)
@@ -658,7 +729,6 @@ rdpRpc* rpc_new(rdpTransport* transport)
        if (rpc_client_new(rpc) < 0)
                goto out_free_virtualConnectionCookieTable;
 
-       rpc->client->SynchronousSend = TRUE;
        rpc->client->SynchronousReceive = TRUE;
        return rpc;
 out_free_virtualConnectionCookieTable:
index 0a730bf..488d82d 100644 (file)
@@ -706,8 +706,6 @@ struct rpc_client
        HANDLE Thread;
        HANDLE StopEvent;
 
-       wQueue* SendQueue;
-
        RPC_PDU* pdu;
        wQueue* ReceivePool;
        wQueue* ReceiveQueue;
@@ -719,9 +717,6 @@ struct rpc_client
 
        wArrayList* ClientCallList;
 
-       HANDLE PduSentEvent;
-
-       BOOL SynchronousSend;
        BOOL SynchronousReceive;
 };
 typedef struct rpc_client RpcClient;
index 7ede69d..e568f9d 100644 (file)
@@ -107,6 +107,7 @@ const p_uuid_t BTFN_UUID =
 
 int rpc_send_bind_pdu(rdpRpc* rpc)
 {
+       int status;
        BYTE* buffer;
        UINT32 offset;
        UINT32 length;
@@ -269,15 +270,14 @@ int rpc_send_bind_pdu(rdpRpc* rpc)
                return -1;
        }
 
-       if (rpc_send_enqueue_pdu(rpc, buffer, length) != 0)
-               length = -1;
+       status = rpc_send_pdu(rpc, buffer, length);
 
        free(bind_pdu->p_context_elem.p_cont_elem[0].transfer_syntaxes);
        free(bind_pdu->p_context_elem.p_cont_elem[1].transfer_syntaxes);
        free(bind_pdu->p_context_elem.p_cont_elem);
        free(bind_pdu);
 
-       return length;
+       return status;
 }
 
 /**
@@ -339,6 +339,7 @@ int rpc_send_rpc_auth_3_pdu(rdpRpc* rpc)
        int status;
        BYTE* buffer;
        UINT32 offset;
+       UINT32 length;
        RpcClientCall* clientCall;
        rpcconn_rpc_auth_3_hdr_t* auth_3_pdu;
 
@@ -386,13 +387,12 @@ int rpc_send_rpc_auth_3_pdu(rdpRpc* rpc)
        CopyMemory(&buffer[offset + 8], auth_3_pdu->auth_verifier.auth_value, auth_3_pdu->auth_length);
        offset += (8 + auth_3_pdu->auth_length);
 
-       status = (int) auth_3_pdu->frag_length;
+       length = auth_3_pdu->frag_length;
 
        clientCall = rpc_client_call_new(auth_3_pdu->call_id, 0);
        ArrayList_Add(rpc->client->ClientCallList, clientCall);
 
-       if (rpc_send_enqueue_pdu(rpc, buffer, (UINT32) status) != 0)
-               status = -1;
+       status = rpc_send_pdu(rpc, buffer, length);
 
        free(auth_3_pdu);
 
index 601b112..4849199 100644 (file)
 
 #define SYNCHRONOUS_TIMEOUT 5000
 
-RPC_PDU* rpc_client_receive_pool_take(rdpRpc* rpc)
+RPC_PDU* rpc_pdu_new()
 {
-       RPC_PDU* pdu = NULL;
+       RPC_PDU* pdu;
 
-       if (WaitForSingleObject(Queue_Event(rpc->client->ReceivePool), 0) == WAIT_OBJECT_0)
-               pdu = Queue_Dequeue(rpc->client->ReceivePool);
+       pdu = (RPC_PDU*) malloc(sizeof(RPC_PDU));
 
        if (!pdu)
-       {
-               pdu = (RPC_PDU*) malloc(sizeof(RPC_PDU));
-
-               if (!pdu)
-                       return NULL;
+               return NULL;
 
-               pdu->s = Stream_New(NULL, rpc->max_recv_frag);
+       pdu->s = Stream_New(NULL, 4096);
 
-               if (!pdu->s)
-               {
-                       free(pdu);
-                       return NULL;
-               }
+       if (!pdu->s)
+       {
+               free(pdu);
+               return NULL;
        }
 
+       pdu->Type = 0;
+       pdu->Flags = 0;
        pdu->CallId = 0;
+
+       return pdu;
+}
+
+static void rpc_pdu_free(RPC_PDU* pdu)
+{
+       if (!pdu)
+               return;
+
+       Stream_Free(pdu->s, TRUE);
+       free(pdu);
+}
+
+RPC_PDU* rpc_client_receive_pool_take(rdpRpc* rpc)
+{
+       RPC_PDU* pdu = NULL;
+
+       if (WaitForSingleObject(Queue_Event(rpc->client->ReceivePool), 0) == WAIT_OBJECT_0)
+               pdu = Queue_Dequeue(rpc->client->ReceivePool);
+
+       if (!pdu)
+               pdu = rpc_pdu_new();
+
+       pdu->Type = 0;
        pdu->Flags = 0;
-       Stream_Length(pdu->s) = 0;
+       pdu->CallId = 0;
+
        Stream_SetPosition(pdu->s, 0);
+
        return pdu;
 }
 
@@ -119,13 +141,13 @@ int rpc_client_receive_pipe_read(rdpRpc* rpc, BYTE* buffer, size_t length)
        return status;
 }
 
-int rpc_client_on_pdu_received(rdpRpc* rpc, RPC_PDU* pdu)
+int rpc_client_recv_pdu(rdpRpc* rpc, RPC_PDU* pdu)
 {
        Queue_Enqueue(rpc->client->ReceiveQueue, pdu);
        return 1;
 }
 
-int rpc_client_on_fragment_received(rdpRpc* rpc, wStream* fragment)
+int rpc_client_recv_fragment(rdpRpc* rpc, wStream* fragment)
 {
        BYTE* buffer;
        RPC_PDU* pdu;
@@ -203,7 +225,7 @@ int rpc_client_on_fragment_received(rdpRpc* rpc, wStream* fragment)
                                pdu->Type = PTYPE_RESPONSE;
                                pdu->CallId = rpc->StubCallId;
                                Stream_SealLength(pdu->s);
-                               rpc_client_on_pdu_received(rpc, pdu);
+                               rpc_client_recv_pdu(rpc, pdu);
                                rpc->client->pdu = NULL;
                                rpc->StubFragCount = 0;
                                rpc->StubCallId = 0;
@@ -238,7 +260,7 @@ int rpc_client_on_fragment_received(rdpRpc* rpc, wStream* fragment)
                        Stream_EnsureCapacity(pdu->s, Stream_Length(fragment));
                        Stream_Write(pdu->s, buffer, Stream_Length(fragment));
                        Stream_SealLength(pdu->s);
-                       rpc_client_on_pdu_received(rpc, pdu);
+                       rpc_client_recv_pdu(rpc, pdu);
                        rpc->client->pdu = NULL;
                        return 0;
                }
@@ -264,7 +286,7 @@ int rpc_client_on_fragment_received(rdpRpc* rpc, wStream* fragment)
                Stream_EnsureCapacity(pdu->s, Stream_Length(fragment));
                Stream_Write(pdu->s, buffer, Stream_Length(fragment));
                Stream_SealLength(pdu->s);
-               rpc_client_on_pdu_received(rpc, pdu);
+               rpc_client_recv_pdu(rpc, pdu);
                rpc->client->pdu = NULL;
                return 0;
        }
@@ -281,7 +303,7 @@ int rpc_client_on_fragment_received(rdpRpc* rpc, wStream* fragment)
        return 0;
 }
 
-int rpc_client_on_read(rdpRpc* rpc)
+int rpc_client_recv(rdpRpc* rpc)
 {
        int position;
        int status = -1;
@@ -347,7 +369,7 @@ int rpc_client_on_read(rdpRpc* rpc)
                        Stream_SealLength(rpc->client->ReceiveFragment);
                        Stream_SetPosition(rpc->client->ReceiveFragment, 0);
 
-                       status = rpc_client_on_fragment_received(rpc, rpc->client->ReceiveFragment);
+                       status = rpc_client_recv_fragment(rpc, rpc->client->ReceiveFragment);
 
                        if (status < 0)
                                return status;
@@ -411,65 +433,18 @@ void rpc_client_call_free(RpcClientCall* clientCall)
        free(clientCall);
 }
 
-int rpc_send_enqueue_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
+int rpc_send_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
 {
        int status;
-       RPC_PDU* pdu;
-
-       pdu = (RPC_PDU*) malloc(sizeof(RPC_PDU));
-
-       if (!pdu)
-       {
-               free(buffer);
-               return -1;
-       }
-
-       pdu->s = Stream_New(buffer, length);
-
-       if (!pdu->s)
-               goto out_free;
-
-       if (!Queue_Enqueue(rpc->client->SendQueue, pdu))
-               goto out_free_stream;
-
-       if (rpc->client->SynchronousSend)
-       {
-               status = WaitForSingleObject(rpc->client->PduSentEvent, SYNCHRONOUS_TIMEOUT);
-
-               if (status == WAIT_TIMEOUT)
-               {
-                       WLog_ERR(TAG, "timed out waiting for pdu sent event %p", rpc->client->PduSentEvent);
-                       return -1;
-               }
-
-               ResetEvent(rpc->client->PduSentEvent);
-       }
-
-       return 0;
-out_free_stream:
-       Stream_Free(pdu->s, TRUE);
-out_free:
-       free(pdu);
-       WLog_ERR(TAG, "rpc_send_enqueue_pdu failure");
-       return -1;
-}
-
-int rpc_send_dequeue_pdu(rdpRpc* rpc)
-{
-       int status;
-       RPC_PDU* pdu;
+       RpcInChannel* inChannel;
        RpcClientCall* clientCall;
        rpcconn_common_hdr_t* header;
-       RpcInChannel* inChannel;
 
-       pdu = (RPC_PDU*) Queue_Dequeue(rpc->client->SendQueue);
+       inChannel = rpc->VirtualConnection->DefaultInChannel;
 
-       if (!pdu)
-               return 0;
+       status = rpc_in_write(rpc, buffer, length);
 
-       inChannel = rpc->VirtualConnection->DefaultInChannel;
-       status = rpc_in_write(rpc, Stream_Buffer(pdu->s), Stream_Length(pdu->s));
-       header = (rpcconn_common_hdr_t*) Stream_Buffer(pdu->s);
+       header = (rpcconn_common_hdr_t*) buffer;
        clientCall = rpc_client_call_find_by_id(rpc, header->call_id);
        clientCall->State = RPC_CLIENT_CALL_STATE_DISPATCHED;
 
@@ -486,11 +461,7 @@ int rpc_send_dequeue_pdu(rdpRpc* rpc)
                inChannel->SenderAvailableWindow -= status;
        }
 
-       Stream_Free(pdu->s, TRUE);
-       free(pdu);
-
-       if (rpc->client->SynchronousSend)
-               SetEvent(rpc->client->PduSentEvent);
+       free(buffer);
 
        return status;
 }
@@ -531,7 +502,6 @@ static void* rpc_client_thread(void* arg)
 
        nCount = 0;
        events[nCount++] = rpc->client->StopEvent;
-       events[nCount++] = Queue_Event(rpc->client->SendQueue);
        events[nCount++] = ReadEvent;
 
        /*
@@ -541,7 +511,7 @@ static void* rpc_client_thread(void* arg)
         * the problem for now.
         */
 
-       if (rpc_client_on_read(rpc) < 0)
+       if (rpc_client_recv(rpc) < 0)
        {
                rpc->transport->layer = TRANSPORT_LAYER_CLOSED;
                return NULL;
@@ -556,31 +526,17 @@ static void* rpc_client_thread(void* arg)
 
                if (WaitForSingleObject(ReadEvent, 0) == WAIT_OBJECT_0)
                {
-                       if (rpc_client_on_read(rpc) < 0)
+                       if (rpc_client_recv(rpc) < 0)
                        {
                                rpc->transport->layer = TRANSPORT_LAYER_CLOSED;
                                break;
                        }
                }
-
-               if (WaitForSingleObject(Queue_Event(rpc->client->SendQueue), 0) == WAIT_OBJECT_0)
-               {
-                       rpc_send_dequeue_pdu(rpc);
-               }
        }
 
        return NULL;
 }
 
-static void rpc_pdu_free(RPC_PDU* pdu)
-{
-       if (!pdu)
-               return;
-
-       Stream_Free(pdu->s, TRUE);
-       free(pdu);
-}
-
 int rpc_client_new(rdpRpc* rpc)
 {
        RpcClient* client;
@@ -597,18 +553,6 @@ int rpc_client_new(rdpRpc* rpc)
        if (!client->StopEvent)
                return -1;
 
-       client->PduSentEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
-
-       if (!client->PduSentEvent)
-               return -1;
-
-       client->SendQueue = Queue_New(TRUE, -1, -1);
-
-       if (!client->SendQueue)
-               return -1;
-
-       Queue_Object(client->SendQueue)->fnObjectFree = (OBJECT_FREE_FN) rpc_pdu_free;
-
        client->pdu = NULL;
 
        client->ReceivePool = Queue_New(TRUE, -1, -1);
@@ -679,9 +623,6 @@ int rpc_client_free(rdpRpc* rpc)
 
        rpc_client_stop(rpc);
 
-       if (client->SendQueue)
-               Queue_Free(client->SendQueue);
-
        if (client->ReceiveFragment)
                Stream_Free(client->ReceiveFragment, TRUE);
 
@@ -707,9 +648,6 @@ int rpc_client_free(rdpRpc* rpc)
        if (client->StopEvent)
                CloseHandle(client->StopEvent);
 
-       if (client->PduSentEvent)
-               CloseHandle(client->PduSentEvent);
-
        if (client->Thread)
                CloseHandle(client->Thread);
 
index 88da091..edafaa3 100644 (file)
@@ -35,6 +35,7 @@ RpcClientCall* rpc_client_call_find_by_id(rdpRpc* rpc, UINT32 CallId);
 RpcClientCall* rpc_client_call_new(UINT32 CallId, UINT32 OpNum);
 void rpc_client_call_free(RpcClientCall* client_call);
 
+int rpc_send_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length);
 int rpc_send_enqueue_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length);
 int rpc_send_dequeue_pdu(rdpRpc* rpc);
 
index b0bede1..9296f20 100644 (file)
 
 BOOL rts_connect(rdpRpc* rpc)
 {
-       RPC_PDU* pdu;
-       rpcconn_rts_hdr_t* rts;
-       HttpResponse* httpResponse;
+       HttpResponse* response;
        freerdp* instance = (freerdp*) rpc->settings->instance;
        rdpContext* context = instance->context;
 
-       /**
-        * Connection Opening
-        *
-        * When opening a virtual connection to the server, an implementation of this protocol MUST perform
-        * the following sequence of steps:
-        *
-        * 1. Send an IN channel request as specified in section 2.1.2.1.1, containing the connection timeout,
-        *    ResourceType UUID, and Session UUID values, if any, supplied by the higher-layer protocol or application.
-        *
-        * 2. Send an OUT channel request as specified in section 2.1.2.1.2.
-        *
-        * 3. Send a CONN/A1 RTS PDU as specified in section 2.2.4.2
-        *
-        * 4. Send a CONN/B1 RTS PDU as specified in section 2.2.4.5
-        *
-        * 5. Wait for the connection establishment protocol sequence as specified in 3.2.1.5.3.1 to complete
-        *
-        * An implementation MAY execute steps 1 and 2 in parallel. An implementation SHOULD execute steps
-        * 3 and 4 in parallel. An implementation MUST execute step 3 after completion of step 1 and execute
-        * step 4 after completion of step 2.
-        *
-        */
-
        rpc->VirtualConnection->State = VIRTUAL_CONNECTION_STATE_INITIAL;
        WLog_DBG(TAG, "VIRTUAL_CONNECTION_STATE_INITIAL");
 
@@ -100,7 +75,7 @@ BOOL rts_connect(rdpRpc* rpc)
                return FALSE;
        }
 
-       if (rts_send_CONN_A1_pdu(rpc) != 0)
+       if (rts_send_CONN_A1_pdu(rpc) < 0)
        {
                WLog_ERR(TAG, "rpc_send_CONN_A1_pdu error!");
                return FALSE;
@@ -121,49 +96,21 @@ BOOL rts_connect(rdpRpc* rpc)
        rpc->VirtualConnection->State = VIRTUAL_CONNECTION_STATE_OUT_CHANNEL_WAIT;
        WLog_DBG(TAG, "VIRTUAL_CONNECTION_STATE_OUT_CHANNEL_WAIT");
 
-       /**
-        * Receive OUT Channel Response
-        *
-        * A client implementation MUST NOT accept the OUT channel HTTP response in any state other than
-        * Out Channel Wait. If received in any other state, this HTTP response is a protocol error. Therefore,
-        * the client MUST consider the virtual connection opening a failure and indicate this to higher layers
-        * in an implementation-specific way. The Microsoft Windows implementation returns
-        * RPC_S_PROTOCOL_ERROR, as specified in [MS-ERREF], to higher-layer protocols.
-        *
-        * If this HTTP response is received in Out Channel Wait state, the client MUST process the fields of
-        * this response as defined in this section.
-        *
-        * First, the client MUST determine whether the response indicates a success or a failure. If the status
-        * code is set to 200, the client MUST interpret this as a success, and it MUST do the following:
-        *
-        * 1. Ignore the values of all other header fields.
-        *
-        * 2. Transition to Wait_A3W state.
-        *
-        * 3. Wait for network events.
-        *
-        * 4. Skip the rest of the processing in this section.
-        *
-        * If the status code is not set to 200, the client MUST interpret this as a failure and follow the same
-        * processing rules as specified in section 3.2.2.5.6.
-        *
-        */
-
-       httpResponse = http_response_recv(rpc->TlsOut);
+       response = http_response_recv(rpc->TlsOut);
 
-       if (!httpResponse)
+       if (!response)
        {
                WLog_ERR(TAG, "unable to retrieve OUT Channel Response!");
                return FALSE;
        }
 
-       if (httpResponse->StatusCode != HTTP_STATUS_OK)
+       if (response->StatusCode != HTTP_STATUS_OK)
        {
-               WLog_ERR(TAG, "error! Status Code: %d", httpResponse->StatusCode);
-               http_response_print(httpResponse);
-               http_response_free(httpResponse);
+               WLog_ERR(TAG, "error! Status Code: %d", response->StatusCode);
+               http_response_print(response);
+               http_response_free(response);
 
-               if (httpResponse->StatusCode == HTTP_STATUS_DENIED)
+               if (response->StatusCode == HTTP_STATUS_DENIED)
                {
                        if (!connectErrorCode)
                        {
@@ -179,92 +126,11 @@ BOOL rts_connect(rdpRpc* rpc)
                return FALSE;
        }
 
-       http_response_free(httpResponse);
+       http_response_free(response);
 
        rpc->VirtualConnection->State = VIRTUAL_CONNECTION_STATE_WAIT_A3W;
        WLog_DBG(TAG, "VIRTUAL_CONNECTION_STATE_WAIT_A3W");
 
-       /**
-        * Receive CONN_A3 RTS PDU
-        *
-        * A client implementation MUST NOT accept the CONN/A3 RTS PDU in any state other than
-        * Wait_A3W. If received in any other state, this PDU is a protocol error and the client
-        * MUST consider the virtual connection opening a failure and indicate this to higher
-        * layers in an implementation-specific way.
-        *
-        * Set the ConnectionTimeout in the Ping Originator of the Client's IN Channel to the
-        * ConnectionTimeout in the CONN/A3 PDU.
-        *
-        * If this RTS PDU is received in Wait_A3W state, the client MUST transition the state
-        * machine to Wait_C2 state and wait for network events.
-        *
-        */
-
-       rpc_client_start(rpc);
-
-       pdu = rpc_recv_dequeue_pdu(rpc, TRUE);
-
-       if (!pdu)
-               return FALSE;
-
-       rts = (rpcconn_rts_hdr_t*) Stream_Buffer(pdu->s);
-
-       if (!rts_match_pdu_signature(rpc, &RTS_PDU_CONN_A3_SIGNATURE, rts))
-       {
-               WLog_ERR(TAG, "unexpected RTS PDU: Expected CONN/A3");
-               return FALSE;
-       }
-
-       rts_recv_CONN_A3_pdu(rpc, Stream_Buffer(pdu->s), Stream_Length(pdu->s));
-
-       rpc_client_receive_pool_return(rpc, pdu);
-
-       rpc->VirtualConnection->State = VIRTUAL_CONNECTION_STATE_WAIT_C2;
-       WLog_DBG(TAG, "VIRTUAL_CONNECTION_STATE_WAIT_C2");
-
-       /**
-        * Receive CONN_C2 RTS PDU
-        *
-        * A client implementation MUST NOT accept the CONN/C2 RTS PDU in any state other than Wait_C2.
-        * If received in any other state, this PDU is a protocol error and the client MUST consider the virtual
-        * connection opening a failure and indicate this to higher layers in an implementation-specific way.
-        *
-        * If this RTS PDU is received in Wait_C2 state, the client implementation MUST do the following:
-        *
-        * 1. Transition the state machine to opened state.
-        *
-        * 2. Set the connection time-out protocol variable to the value of the ConnectionTimeout field from
-        *    the CONN/C2 RTS PDU.
-        *
-        * 3. Set the PeerReceiveWindow value in the SendingChannel of the Client IN Channel to the
-        *    ReceiveWindowSize value in the CONN/C2 PDU.
-        *
-        * 4. Indicate to higher-layer protocols that the virtual connection opening is a success.
-        *
-        */
-
-       pdu = rpc_recv_dequeue_pdu(rpc, TRUE);
-
-       if (!pdu)
-               return FALSE;
-
-       rts = (rpcconn_rts_hdr_t*) Stream_Buffer(pdu->s);
-
-       if (!rts_match_pdu_signature(rpc, &RTS_PDU_CONN_C2_SIGNATURE, rts))
-       {
-               WLog_ERR(TAG, "unexpected RTS PDU: Expected CONN/C2");
-               return FALSE;
-       }
-
-       rts_recv_CONN_C2_pdu(rpc, Stream_Buffer(pdu->s), Stream_Length(pdu->s));
-
-       rpc_client_receive_pool_return(rpc, pdu);
-
-       rpc->VirtualConnection->State = VIRTUAL_CONNECTION_STATE_OPENED;
-       WLog_DBG(TAG, "VIRTUAL_CONNECTION_STATE_OPENED");
-
-       rpc->State = RPC_CLIENT_STATE_ESTABLISHED;
-
        return TRUE;
 }
 
@@ -685,6 +551,7 @@ int rts_send_CONN_A1_pdu(rdpRpc* rpc)
        ReceiveWindowSize = rpc->VirtualConnection->DefaultOutChannel->ReceiveWindow;
 
        buffer = (BYTE*) malloc(header.frag_length);
+
        if (!buffer)
                return -1;
 
@@ -718,13 +585,13 @@ int rts_recv_CONN_A3_pdu(rdpRpc* rpc, BYTE* buffer, UINT32 length)
 
 int rts_send_CONN_B1_pdu(rdpRpc* rpc)
 {
+       int status;
        BYTE* buffer;
        UINT32 length;
        rpcconn_rts_hdr_t header;
        BYTE* INChannelCookie;
        BYTE* AssociationGroupId;
        BYTE* VirtualConnectionCookie;
-       int status;
 
        rts_pdu_header_init(&header);
        header.frag_length = 104;
@@ -741,6 +608,7 @@ int rts_send_CONN_B1_pdu(rdpRpc* rpc)
        AssociationGroupId = (BYTE*) &(rpc->VirtualConnection->AssociationGroupId);
 
        buffer = (BYTE*) malloc(header.frag_length);
+
        if (!buffer)
                return -1;
 
@@ -804,8 +672,10 @@ int rts_send_keep_alive_pdu(rdpRpc* rpc)
        WLog_DBG(TAG, "Sending Keep-Alive RTS PDU");
 
        buffer = (BYTE*) malloc(header.frag_length);
+
        if (!buffer)
                return -1;
+
        CopyMemory(buffer, ((BYTE*) &header), 20); /* RTS Header (20 bytes) */
        rts_client_keepalive_command_write(&buffer[20], rpc->CurrentKeepAliveInterval); /* ClientKeepAlive (8 bytes) */
 
index 7edb5c3..f3ae7be 100644 (file)
@@ -1506,7 +1506,6 @@ int tsg_write(rdpTsg* tsg, BYTE* data, UINT32 length)
 
 BOOL tsg_set_blocking_mode(rdpTsg* tsg, BOOL blocking)
 {
-       tsg->rpc->client->SynchronousSend = TRUE;
        tsg->rpc->client->SynchronousReceive = blocking;
        tsg->transport->GatewayEvent = tsg->rpc->client->PipeEvent;
        return TRUE;