winhttp: Implement WinHttpOpen and WinHttpCloseHandle.
[wine/wine-kai.git] / dlls / winhttp / session.c
blob76a878e5bd728eda9f9d6135ba3c00daf464976b
1 /*
2 * Copyright 2008 Hans Leidekker for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
20 #include "wine/port.h"
21 #include "wine/debug.h"
23 #include <stdarg.h>
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winnls.h"
28 #include "winhttp.h"
30 #include "winhttp_private.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(winhttp);
34 static void set_last_error( DWORD error )
36 /* FIXME */
37 SetLastError( error );
40 /***********************************************************************
41 * WinHttpCheckPlatform (winhttp.@)
43 BOOL WINAPI WinHttpCheckPlatform( void )
45 TRACE("\n");
46 return TRUE;
49 /***********************************************************************
50 * session_destroy (internal)
52 static void session_destroy( object_header_t *hdr )
54 session_t *session = (session_t *)hdr;
56 TRACE("%p\n", session);
58 heap_free( session->agent );
59 heap_free( session->proxy_server );
60 heap_free( session->proxy_bypass );
61 heap_free( session->proxy_username );
62 heap_free( session->proxy_password );
63 heap_free( session );
66 static const object_vtbl_t session_vtbl =
68 session_destroy,
69 NULL,
70 NULL
73 /***********************************************************************
74 * WinHttpOpen (winhttp.@)
76 HINTERNET WINAPI WinHttpOpen( LPCWSTR agent, DWORD access, LPCWSTR proxy, LPCWSTR bypass, DWORD flags )
78 session_t *session;
79 HINTERNET handle = NULL;
81 TRACE("%s, %u, %s, %s, 0x%08x\n", debugstr_w(agent), access, debugstr_w(proxy), debugstr_w(bypass), flags);
83 if (!(session = heap_alloc_zero( sizeof(session_t) ))) return NULL;
85 session->hdr.type = WINHTTP_HANDLE_TYPE_SESSION;
86 session->hdr.vtbl = &session_vtbl;
87 session->hdr.flags = flags;
88 session->hdr.refs = 1;
89 session->access = access;
91 if (agent && !(session->agent = strdupW( agent ))) goto end;
92 if (proxy && !(session->proxy_server = strdupW( proxy ))) goto end;
93 if (bypass && !(session->proxy_bypass = strdupW( bypass ))) goto end;
95 if (!(handle = alloc_handle( &session->hdr ))) goto end;
96 session->hdr.handle = handle;
98 end:
99 release_object( &session->hdr );
100 TRACE("returning %p\n", handle);
101 return handle;
104 /***********************************************************************
105 * WinHttpCloseHandle (winhttp.@)
107 BOOL WINAPI WinHttpCloseHandle( HINTERNET handle )
109 object_header_t *hdr;
111 TRACE("%p\n", handle);
113 if (!(hdr = grab_object( handle )))
115 set_last_error( ERROR_INVALID_HANDLE );
116 return FALSE;
118 release_object( hdr );
119 free_handle( handle );
120 return TRUE;