Module: wine Branch: master Commit: a30ffca108d905e4e77d1cc6651722d8ce671085 URL: http://source.winehq.org/git/wine.git/?a=commit;h=a30ffca108d905e4e77d1cc665...
Author: Jacek Caban jacek@codeweavers.com Date: Mon Mar 2 03:20:09 2009 +0100
urlmon: Move close_connection implementation to common Protocol object.
---
dlls/urlmon/http.c | 61 ++++++++++++++++++++++----------------------- dlls/urlmon/protocol.c | 14 ++++++++++ dlls/urlmon/urlmon_main.h | 9 ++++++ 3 files changed, 53 insertions(+), 31 deletions(-)
diff --git a/dlls/urlmon/http.c b/dlls/urlmon/http.c index ab5aa38..5d102a6 100644 --- a/dlls/urlmon/http.c +++ b/dlls/urlmon/http.c @@ -80,9 +80,32 @@ typedef struct { static const WCHAR wszHeaders[] = {'A','c','c','e','p','t','-','E','n','c','o','d','i','n','g', ':',' ','g','z','i','p',',',' ','d','e','f','l','a','t','e',0};
-/* - * Helpers - */ +#define ASYNCPROTOCOL_THIS(iface) DEFINE_THIS2(HttpProtocol, base, iface) + +static void HttpProtocol_close_connection(Protocol *prot) +{ + HttpProtocol *This = ASYNCPROTOCOL_THIS(prot); + + if(This->connection) + InternetCloseHandle(This->connection); + + if(This->http_negotiate) { + IHttpNegotiate_Release(This->http_negotiate); + This->http_negotiate = 0; + } + + if(This->full_header) { + if(This->full_header != wszHeaders) + heap_free(This->full_header); + This->full_header = 0; + } +} + +#undef ASYNCPROTOCOL_THIS + +static const ProtocolVtbl AsyncProtocolVtbl = { + HttpProtocol_close_connection +};
static void HTTPPROTOCOL_ReportResult(HttpProtocol *This, HRESULT hres) { @@ -129,31 +152,6 @@ static void HTTPPROTOCOL_AllDataRead(HttpProtocol *This) HTTPPROTOCOL_ReportResult(This, S_OK); }
-static void HTTPPROTOCOL_Close(HttpProtocol *This) -{ - if (This->http_negotiate) - { - IHttpNegotiate_Release(This->http_negotiate); - This->http_negotiate = 0; - } - if (This->base.request) - InternetCloseHandle(This->base.request); - if (This->connection) - InternetCloseHandle(This->connection); - if (This->base.internet) - { - InternetCloseHandle(This->base.internet); - This->base.internet = 0; - } - if (This->full_header) - { - if (This->full_header != wszHeaders) - heap_free(This->full_header); - This->full_header = 0; - } - This->base.flags = 0; -} - static void CALLBACK HTTPPROTOCOL_InternetStatusCallback( HINTERNET hInternet, DWORD_PTR dwContext, DWORD dwInternetStatus, LPVOID lpvStatusInformation, DWORD dwStatusInformationLength) @@ -269,7 +267,7 @@ static ULONG WINAPI HttpProtocol_Release(IInternetProtocol *iface) TRACE("(%p) ref=%d\n", This, ref);
if(!ref) { - HTTPPROTOCOL_Close(This); + protocol_close_connection(&This->base); heap_free(This);
URLMON_UnlockModule(); @@ -523,7 +521,7 @@ done: if (hres != S_OK) { IInternetProtocolSink_ReportResult(This->base.protocol_sink, hres, 0, NULL); - HTTPPROTOCOL_Close(This); + protocol_close_connection(&This->base); }
CoTaskMemFree(post_cookie); @@ -714,8 +712,8 @@ static HRESULT WINAPI HttpProtocol_Terminate(IInternetProtocol *iface, DWORD dwO HttpProtocol *This = PROTOCOL_THIS(iface);
TRACE("(%p)->(%08x)\n", This, dwOptions); - HTTPPROTOCOL_Close(This);
+ protocol_close_connection(&This->base); return S_OK; }
@@ -915,6 +913,7 @@ static HRESULT create_http_protocol(BOOL https, void **ppobj) if(!ret) return E_OUTOFMEMORY;
+ ret->base.vtbl = &AsyncProtocolVtbl; ret->lpInternetProtocolVtbl = &HttpProtocolVtbl; ret->lpInternetPriorityVtbl = &HttpPriorityVtbl;
diff --git a/dlls/urlmon/protocol.c b/dlls/urlmon/protocol.c index b25c9de..a2e801b 100644 --- a/dlls/urlmon/protocol.c +++ b/dlls/urlmon/protocol.c @@ -42,3 +42,17 @@ HRESULT protocol_unlock_request(Protocol *protocol)
return S_OK; } + +void protocol_close_connection(Protocol *protocol) +{ + protocol->vtbl->close_connection(protocol); + + if(protocol->request) + InternetCloseHandle(protocol->request); + if(protocol->internet) { + InternetCloseHandle(protocol->internet); + protocol->internet = 0; + } + + protocol->flags = 0; +} diff --git a/dlls/urlmon/urlmon_main.h b/dlls/urlmon/urlmon_main.h index 906cd31..6519630 100644 --- a/dlls/urlmon/urlmon_main.h +++ b/dlls/urlmon/urlmon_main.h @@ -79,7 +79,11 @@ HRESULT bind_to_object(IMoniker *mon, LPCWSTR url, IBindCtx *pbc, REFIID riid, v HRESULT create_binding_protocol(LPCWSTR url, BOOL from_urlmon, IInternetProtocol **protocol); void set_binding_sink(IInternetProtocol *bind_protocol, IInternetProtocolSink *sink);
+typedef struct ProtocolVtbl ProtocolVtbl; + typedef struct { + const ProtocolVtbl *vtbl; + IInternetProtocol *protocol; IInternetProtocolSink *protocol_sink;
@@ -98,8 +102,13 @@ typedef struct { LONG priority; } Protocol;
+struct ProtocolVtbl { + void (*close_connection)(Protocol*); +}; + HRESULT protocol_lock_request(Protocol*); HRESULT protocol_unlock_request(Protocol*); +void protocol_close_connection(Protocol*);
static inline void *heap_alloc(size_t len) {