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
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109 #ifndef INC_MI32_HTTPCLIENT_H
00110 #define INC_MI32_HTTPCLIENT_H
00111
00112 #ifndef INC_MI32_HTTPMSG_H
00113 #include <mi32/httpmsg.h>
00114 #endif
00115
00116 #ifndef INC_MI32_STRUTF8_H
00117 #include <mi32/strutf8.h>
00118 #endif
00119
00120 #ifndef INC_MI32_DELEGATE_H
00121 #include <mi32/delegate.h>
00122 #endif
00123
00124 #ifdef MISYSTEMDLL
00125 #define CLASSLIBEXPORT MI_DLLCLASSEXPORT
00126 #else
00127 #define CLASSLIBEXPORT MI_DLLCLASSIMPORT
00128 #endif
00129
00130 #ifndef GENERATING_DOXYGEN_OUTPUT
00131
00132 class MISOCKET;
00133 class XMLDOC;
00134 class FILEPATH;
00135 class GENERICRW;
00136 class STATUSCONTEXT;
00137 #endif
00138
00139
00140
00142 class CLASSLIBEXPORT HTTPCLIENT {
00143 public:
00144
00145 typedef fastdelegate::FastDelegate<ERRVALUE (const MISTRING& host, const MISTRING& realm)> DELEGATE_ONAUTHREQUEST;
00146 typedef fastdelegate::FastDelegate<bool(double)> DELEGATE_ONSTATUS;
00147
00148 class INSTANCEDATA;
00149
00150 enum CACHEMODE {
00151 CACHEMODE_NoCache = 0,
00152 CACHEMODE_IgnoreCache = 1,
00153 CACHEMODE_UseCacheIfCurrent = 2,
00154 CACHEMODE_UseCacheIfExists = 3
00155 };
00156
00157 enum STATE {
00158 STATE_Idle,
00159 STATE_WaitingForFirstLine,
00160 STATE_ReadingHeader,
00161 STATE_ReadingMessage
00162 };
00163
00165 static void CacheClear ();
00166
00168 static bool CacheIsDisabled ();
00169
00171 static void CacheSetDisabled (
00172 bool disable
00173 );
00174
00177 static INT32 GetCacheMaxSize ();
00178
00183 static const char* GetDefaultStatusMessage (
00184 int code
00185 );
00186
00188 static void RegisterDelegateOnAuthRequest (
00189 DELEGATE_ONAUTHREQUEST delegate
00190 );
00191
00196 static void SetCacheMaxSize (
00197 INT32 Size
00198 );
00199
00200
00202 HTTPCLIENT ();
00203
00207 HTTPCLIENT (
00208 MISOCKET *socket,
00209 bool bTakeOwnership
00210 );
00211
00213 virtual ~HTTPCLIENT ();
00214
00218 ERRVALUE ConnectToHost (
00219 const char *hostname,
00220 int port = 80
00221 );
00222
00239 ERRVALUE Download (
00240 const char *path,
00241 HTTPMESSAGE& reply
00242 );
00243
00260 ERRVALUE Download (
00261 const char *path,
00262 bool bIsEscaped,
00263 HTTPMESSAGE& reply
00264 );
00265
00273 ERRVALUE Download (
00274 const HTTPMESSAGE& request,
00275 HTTPMESSAGE& reply
00276 );
00277
00285 ERRVALUE DownloadFile (
00286 const char *path,
00287 FILEPATH& filepath,
00288 const MILIST<STRUTF8>& Headers,
00289 bool bIgnoreCache = false
00290 );
00291
00292 ERRVALUE DownloadFile (
00293 const char *path,
00294 FILEPATH& filepath,
00295 const MILIST<STRUTF8>& Headers,
00296 HTTPMESSAGE& Reply,
00297 bool bIgnoreCache = false
00298 );
00299
00300 ERRVALUE GetAuthentication (
00301 const MISTRING& host,
00302 const MISTRING& realm,
00303 MISTRING& username,
00304 MISTRING& password
00305 );
00306
00307 ERRVALUE GetAuthHeader (
00308 const HTTPMESSAGE& req,
00309 const HTTPMESSAGE& rep,
00310 MISTRING& header
00311 );
00312
00314 CACHEMODE GetCacheMode (
00315 ) const;
00316
00317 const MISTRING& GetHostName () const;
00318
00325 INSTANCEDATA* GetInstanceData (
00326 const char *id
00327 ) const;
00328
00331 ERRVALUE GetMsg (
00332 HTTPMESSAGE& obj
00333 );
00334
00335 ERRVALUE PostFile (
00336 const char *path,
00337 FILEPATH& responsefile,
00338 GENERICRW& body,
00339 const MILIST<STRUTF8>& headers,
00340 HTTPMESSAGE& Reply,
00341 bool bIgnoreCache = false
00342 );
00343
00344 ERRVALUE RemoveAuthentication (
00345 const MISTRING& host,
00346 const MISTRING& realm
00347 );
00348
00350 ERRVALUE Send (
00351 const HTTPMESSAGE& Request,
00352 HTTPMESSAGE& Reply
00353 );
00354
00356 ERRVALUE SendMsg (
00357 const HTTPMESSAGE& msg,
00358 bool bHeaderOnly = false
00359 );
00360
00362 ERRVALUE SendMsg (
00363 const HTTPMESSAGE& headers,
00364 const MISTRING& body,
00365 bool bHeaderOnly = false
00366 );
00367
00369 ERRVALUE SendMsg (
00370 const HTTPMESSAGE& headers,
00371 const STRUTF8& body,
00372 bool bHeaderOnly = false
00373 );
00374
00376 ERRVALUE SendMsg (
00377 const HTTPMESSAGE& headers,
00378 const XMLDOC& body,
00379 bool bHeaderOnly = false
00380 );
00381
00384 ERRVALUE SendMsg (
00385 const HTTPMESSAGE& headers,
00386 GENERICRW& body,
00387 bool bHeaderOnly = false
00388 );
00389
00391 ERRVALUE SetAuthentication (
00392 const MISTRING& host,
00393 const MISTRING& realm,
00394 const MISTRING& username,
00395 const MISTRING& password
00396 );
00397
00400 void SetCacheMode (
00401 CACHEMODE mode
00402 );
00403
00411 void SetDelegateOnStatus (
00412 DELEGATE_ONSTATUS delegate
00413 );
00414
00416 void SetDelegateOnStatusBegin (
00417 DELEGATE_VOID_NOPARMS delegate
00418 );
00419
00421 void SetDelegateOnStatusEnd (
00422 DELEGATE_VOID_NOPARMS delegate
00423 );
00424
00430 void SetHostName (
00431 const char *name
00432 );
00433
00436 void SetTimeOut (
00437 int seconds
00438 );
00439
00441 void SetUseProxy (
00442 bool UseProxy,
00443 const char *ProxyHost = 0,
00444 int ProxyPort = 0
00445 );
00446
00447 private:
00448
00449 #ifndef GENERATING_DOXYGEN_OUTPUT
00450 friend class INSTANCEDATA;
00451 class PRIV;
00452 PRIV *m_pPriv;
00453
00454 void AttachInstanceData (
00455 INSTANCEDATA *data
00456 );
00457
00458 void DetachInstanceData (
00459 INSTANCEDATA *data
00460 );
00461
00462
00463 HTTPCLIENT (const HTTPCLIENT&);
00464 HTTPCLIENT& operator= (const HTTPCLIENT&);
00465
00466 #endif // GENERATING_DOXYGEN_OUTPUT
00467
00468
00469
00471 virtual ERRVALUE v_OnAuthRequest (
00472 const MISTRING& host,
00473 const MISTRING& realm
00474 );
00475
00476 };
00477
00478
00483 class CLASSLIBEXPORT HTTPCLIENT::INSTANCEDATA {
00484 public:
00485 INSTANCEDATA (
00486 HTTPCLIENT *client
00487 );
00488
00489 virtual ~INSTANCEDATA();
00490
00492 HTTPCLIENT* GetClient (
00493 ) const;
00494
00497 const STRUTF8& GetID (
00498 ) const;
00499
00500 private:
00501 HTTPCLIENT *m_client;
00502 STRUTF8 m_id;
00503 };
00504
00505
00506
00507
00508 #undef CLASSLIBEXPORT
00509
00510 #endif // INC_MI32_HTTPCLIENT_H