00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00048 #ifndef INETSTL_INCL_INETSTL_NETWORK_HPP_SESSION
00049 #define INETSTL_INCL_INETSTL_NETWORK_HPP_SESSION
00050
00051 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION
00052 # define INETSTL_VER_INETSTL_NETWORK_HPP_SESSION_MAJOR 5
00053 # define INETSTL_VER_INETSTL_NETWORK_HPP_SESSION_MINOR 1
00054 # define INETSTL_VER_INETSTL_NETWORK_HPP_SESSION_REVISION 3
00055 # define INETSTL_VER_INETSTL_NETWORK_HPP_SESSION_EDIT 61
00056 #endif
00057
00058
00059
00060
00061
00062 #ifndef INETSTL_INCL_INETSTL_H_INETSTL
00063 # include <inetstl/inetstl.h>
00064 #endif
00065 #ifndef INETSTL_OS_IS_WINDOWS
00066 # error This file is currently compatible only with the Win32/Win64 API
00067 #endif
00068 #ifndef INETSTL_INCL_INETSTL_FILESYSTEM_HPP_FILESYSTEM_TRAITS
00069 # include <inetstl/filesystem/filesystem_traits.hpp>
00070 #endif
00071 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00072 # ifndef INETSTL_INCL_INETSTL_ERROR_HPP_EXCEPTIONS
00073 # include <inetstl/error/exceptions.hpp>
00074 # endif
00075 #else
00076 # ifndef STLSOFT_INCL_STLSOFT_ERROR_HPP_EXCEPTIONS
00077 # include <stlsoft/error/exceptions.hpp>
00078 # endif
00079 #endif
00080
00081
00082
00083
00084
00085 #ifndef _INETSTL_NO_NAMESPACE
00086 # if defined(_STLSOFT_NO_NAMESPACE) || \
00087 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00088
00089 namespace inetstl
00090 {
00091 # else
00092
00093
00094 namespace stlsoft
00095 {
00096
00097 namespace inetstl_project
00098 {
00099
00100 # endif
00101 #endif
00102
00103
00104
00105
00106
00113 template< ss_typename_param_k C
00114 #ifdef STLSOFT_CF_EXCEPTION_SUPPORT
00115 , ss_typename_param_k X = throw_internet_exception_policy
00116 #else
00117 , ss_typename_param_k X = stlsoft_ns_qual(null_exception_policy)
00118 #endif
00119 , ss_typename_param_k T = filesystem_traits<C>
00120 >
00121 class basic_session
00122 {
00123 public:
00124 typedef C char_type;
00125 typedef X exception_policy_type;
00126 typedef ss_typename_param_k exception_policy_type::thrown_type thrown_type;
00127 typedef T traits_type;
00128 typedef basic_session<C, X, T> class_type;
00129
00130 typedef HINTERNET resource_type;
00131
00132 public:
00140 basic_session();
00152 ss_explicit_k basic_session( char_type const* pcszAgent
00153 , is_dword_t accessType = INTERNET_OPEN_TYPE_PRECONFIG
00154 , char_type const* pcszProxyName = NULL
00155 , char_type const* pcszProxyBypass = NULL
00156 , is_dword_t flags = 0);
00158 ~basic_session() stlsoft_throw_0();
00159
00160
00161 public:
00173 is_bool_t open( char_type const* pcszAgent
00174 , is_dword_t accessType = INTERNET_OPEN_TYPE_PRECONFIG
00175 , char_type const* pcszProxyName = NULL
00176 , char_type const* pcszProxyBypass = NULL
00177 , is_dword_t flags = 0);
00179 void close();
00182 HINTERNET detach();
00183
00184
00185 public:
00187 is_bool_t is_open() const;
00188
00190 HINTERNET get() const;
00191
00195 operator HINTERNET ();
00196
00197
00198 private:
00199 static char_type const *null_string_();
00200
00201
00202 private:
00203 HINTERNET m_hConn;
00204
00205
00206 private:
00207 basic_session(class_type const&);
00208 class_type& operator =(class_type const&);
00209 };
00210
00211
00212
00213
00214
00220 typedef basic_session<is_char_a_t> session_a;
00226 typedef basic_session<is_char_w_t> session_w;
00232 typedef basic_session<TCHAR> session;
00233
00234
00235
00236 template< ss_typename_param_k C
00237 , ss_typename_param_k X
00238 , ss_typename_param_k T
00239 >
00240 inline ss_typename_type_ret_k basic_session<C, X, T>::char_type const* basic_session<C, X, T>::null_string_()
00241 {
00242 static char_type s_null[1] = { 0 };
00243
00244 return s_null;
00245 }
00246
00247 template< ss_typename_param_k C
00248 , ss_typename_param_k X
00249 , ss_typename_param_k T
00250 >
00251 inline basic_session<C, X, T>::basic_session()
00252 : m_hConn(traits_type::internet_open(null_string_(), INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0))
00253 {
00254 if(NULL == m_hConn)
00255 {
00256 exception_policy_type()("Failed to create session", ::GetLastError());
00257 }
00258 }
00259
00260 template< ss_typename_param_k C
00261 , ss_typename_param_k X
00262 , ss_typename_param_k T
00263 >
00264 inline basic_session<C, X, T>::basic_session( char_type const* pcszAgent
00265 , is_dword_t accessType
00266 , char_type const* pcszProxyName
00267 , char_type const* pcszProxyBypass
00268 , is_dword_t flags)
00269 : m_hConn(traits_type::internet_open(pcszAgent, accessType, pcszProxyName, pcszProxyBypass, flags))
00270 {
00271 if(NULL == m_hConn)
00272 {
00273 exception_policy_type()("Failed to create session", ::GetLastError());
00274 }
00275 }
00276
00277 template< ss_typename_param_k C
00278 , ss_typename_param_k X
00279 , ss_typename_param_k T
00280 >
00281 inline basic_session<C, X, T>::~basic_session() stlsoft_throw_0()
00282 {
00283 if(NULL != m_hConn)
00284 {
00285 ::InternetCloseHandle(m_hConn);
00286 }
00287 }
00288
00289 template< ss_typename_param_k C
00290 , ss_typename_param_k X
00291 , ss_typename_param_k T
00292 >
00293 inline is_bool_t basic_session<C, X, T>::open( char_type const* pcszAgent
00294 , is_dword_t accessType
00295 , char_type const* pcszProxyName
00296 , char_type const* pcszProxyBypass
00297 , is_dword_t flags)
00298 {
00299 is_bool_t bRet;
00300
00301 if(is_open())
00302 {
00303 bRet = false;
00304 }
00305 else
00306 {
00307 m_hConn = traits_type::internet_open(pcszAgent, accessType, pcszProxyName, pcszProxyBypass, flags);
00308
00309 if(NULL == m_hConn)
00310 {
00311 exception_policy_type()("Failed to create session", ::GetLastError());
00312
00313 bRet = false;
00314 }
00315 else
00316 {
00317 bRet = true;
00318 }
00319 }
00320
00321 return bRet;
00322 }
00323
00324 template< ss_typename_param_k C
00325 , ss_typename_param_k X
00326 , ss_typename_param_k T
00327 >
00328 inline void basic_session<C, X, T>::close()
00329 {
00330 if(NULL != m_hConn)
00331 {
00332 ::InternetCloseHandle(m_hConn);
00333
00334 m_hConn = NULL;
00335 }
00336 }
00337
00338 template< ss_typename_param_k C
00339 , ss_typename_param_k X
00340 , ss_typename_param_k T
00341 >
00342 inline HINTERNET basic_session<C, X, T>::detach()
00343 {
00344 INETSTL_MESSAGE_ASSERT("Attempting to detach from an empty session", is_open());
00345
00346 HINTERNET hConn = m_hConn;
00347
00348 m_hConn = NULL;
00349
00350 return hConn;
00351 }
00352
00353 template< ss_typename_param_k C
00354 , ss_typename_param_k X
00355 , ss_typename_param_k T
00356 >
00357 inline is_bool_t basic_session<C, X, T>::is_open() const
00358 {
00359 return NULL != m_hConn;
00360 }
00361
00362 template< ss_typename_param_k C
00363 , ss_typename_param_k X
00364 , ss_typename_param_k T
00365 >
00366 inline HINTERNET basic_session<C, X, T>::get() const
00367 {
00368 return m_hConn;
00369 }
00370
00371 template< ss_typename_param_k C
00372 , ss_typename_param_k X
00373 , ss_typename_param_k T
00374 >
00375 inline basic_session<C, X, T>::operator HINTERNET ()
00376 {
00377 return m_hConn;
00378 }
00379
00380
00381
00382 template< ss_typename_param_k C
00383 , ss_typename_param_k X
00384 , ss_typename_param_k T
00385 >
00386 inline HINTERNET get_handle(basic_session<C, X, T> &s)
00387 {
00388 return s;
00389 }
00390
00391
00392
00393 #ifndef _INETSTL_NO_NAMESPACE
00394 # if defined(_STLSOFT_NO_NAMESPACE) || \
00395 defined(STLSOFT_DOCUMENTATION_SKIP_SECTION)
00396 }
00397 # else
00398 }
00399 }
00400 # endif
00401 #endif
00402
00403
00404
00405 #endif
00406
00407