OpendTect  6.3
odnetworkaccess.h
Go to the documentation of this file.
1 #pragma once
2 
3 /*+
4 ________________________________________________________________________
5 
6  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
7  Author: Salil Agarwal
8  Date: Oct 2012
9 ________________________________________________________________________
10 
11 -*/
12 
13 #include "networkmod.h"
14 #include "bufstringset.h"
15 #include "executor.h"
16 #include "uistring.h"
17 #include "ptrman.h"
18 
19 class QByteArray;
20 class QEventLoop;
21 class QFile;
22 class QNetworkAccessManager;
23 class ODNetworkProcess;
24 class DataBuffer;
25 class od_ostream;
26 
27 namespace Network
28 {
29  class HttpRequestProcess;
30 
33  mGlobal(Network) bool downloadFile(const char* url,const char* outpath,
34  uiString& errmsg,TaskRunner* taskr=0);
35 
37  const char* outpath,
38  uiString& errmsg,
39  TaskRunner* taskr=0);
40 
42  BufferStringSet& outpaths,
43  uiString& errmsg,
44  TaskRunner* taskr=0);
45 
46  mGlobal(Network) bool downloadToBuffer(const char* url,DataBuffer&,
47  uiString& errmsg,
48  TaskRunner* taskr=0);
49 
50  mGlobal(Network) bool uploadFile(const char* url,const char* localfname,
51  const char* remotefname,
52  const char* ftype,const IOPar& postvars,
53  uiString& errmsg,TaskRunner* taskr=0,
54  uiString* returnedmessage = 0);
55 
56  mGlobal(Network) bool uploadQuery(const char* url,const IOPar& querypars,
57  uiString& errmsg,TaskRunner* taskr=0,
58  uiString* returnedmessage = 0);
59 
60  mGlobal(Network) bool getRemoteFileSize(const char* url,od_int64& size,
61  uiString& errmsg);
62 
63  mGlobal(Network) bool ping(const char* url, uiString& msg );
64 
65  mGlobal(Network) void setHttpProxy(const char* hostname,int port,
66  bool auth=false,
67  const char* username=0,
68  const char* password=0);
69 
73 
74  inline const char* sKeyUseProxy() { return "Use Proxy"; }
75  inline const char* sKeyUseAuthentication()
76  { return "Use Authentication";}
77  inline const char* sKeyProxyHost()
78  { return "Http Proxy Host"; }
79  inline const char* sKeyProxyPort()
80  { return "Http Proxy Port"; }
81  inline const char* sKeyProxyUserName()
82  { return "Http Proxy User Name"; }
83  inline const char* sKeyProxyPassword()
84  { return "Http Proxy Password"; }
85  inline const char* sKeyCryptProxyPassword()
86  { return "Http Crypt Proxy Password"; }
87 
88  // File:: counterparts
89  mGlobal(Network) bool exists(const char*);
90  mGlobal(Network) od_int64 getFileSize(const char*);
91  mGlobal(Network) bool getContent(const char*,BufferString&);
92 
93 }
94 
98 public:
99  FileDownloader(const char* url);
100  FileDownloader(const char* url,DataBuffer& db);
101  FileDownloader(const BufferStringSet& urls,
102  const BufferStringSet& outputpaths);
103  ~FileDownloader();
104 
105  od_int64 getDownloadSize();
106 
107  uiString message() const;
108  int nextStep();
109  od_int64 nrDone() const;
110  uiString nrDoneText() const;
111  od_int64 totalNr() const;
112 
113 protected:
114 
115  void setSaveAsPaths(const BufferStringSet&,const char*);
116  int errorOccured();
117 
118  bool writeData();
119  bool writeDataToFile(const char* buffer, int size);
120  bool writeDataToBuffer(const char* buffer, int size);
121 
128 
130 
134 };
135 
136 
140 public:
141  DataUploader(const char* url,const DataBuffer& data,
142  BufferString& header);
143  ~DataUploader();
144 
145  uiString message() const;
146  int nextStep();
147  od_int64 nrDone() const;
148  uiString nrDoneText() const;
149  od_int64 totalNr() const;
150 
151 protected:
152 
153  int errorOccured();
154 
155  bool init_;
158 
161 
165 };
166 
167 
169 {
170 public:
171  virtual bool setFromUser() = 0;
172 
173  static void setNetworkUserQuery(NetworkUserQuery*);
174  static NetworkUserQuery* getNetworkUserQuery();
175 protected:
176 
177  static NetworkUserQuery* inst_;
178 };
bool ping(const char *url, uiString &msg)
bool downloadFile(const char *url, const char *outpath, uiString &errmsg, TaskRunner *taskr=0)
#define mExpClass(module)
Definition: commondefs.h:157
uiString msg_
Definition: odnetworkaccess.h:164
bool getContent(const char *, BufferString &)
DataBuffer * databuffer_
Definition: odnetworkaccess.h:126
BufferStringSet saveaspaths_
Definition: odnetworkaccess.h:124
const char * sKeyUseAuthentication()
Definition: odnetworkaccess.h:75
OD class for stream write common access to the user log file, or std::cout in batch progs...
Definition: od_ostream.h:25
const char * sKeyCryptProxyPassword()
Definition: odnetworkaccess.h:85
od_int64 nrdone_
Definition: odnetworkaccess.h:162
const char * sKeyProxyHost()
Definition: odnetworkaccess.h:77
Definition: jobcommunic.h:22
Definition: odnetworkaccess.h:168
>Provides file or data upload facility
Definition: odnetworkaccess.h:138
#define mODTextTranslationClass(clss)
Definition: uistring.h:37
bool exists(const char *)
#define mGlobal(module)
Definition: commondefs.h:160
bool downloadFiles(BufferStringSet &urls, const char *outpath, uiString &errmsg, TaskRunner *taskr=0)
#define od_int64
Definition: plftypes.h:34
const char * sKeyProxyPort()
Definition: odnetworkaccess.h:79
void setHttpProxyFromIOPar(const IOPar &)
void setHttpProxyFromSettings()
>Provides file download facility
Definition: odnetworkaccess.h:96
od_int64 totalnr_
Definition: odnetworkaccess.h:163
Definition: uistring.h:88
Set of BufferString objects.
Definition: bufstringset.h:25
bool init_
Definition: odnetworkaccess.h:155
const char * sKeyProxyUserName()
Definition: odnetworkaccess.h:81
uiString msg_
Definition: odnetworkaccess.h:133
RefMan< Network::HttpRequestProcess > odnr_
Definition: odnetworkaccess.h:129
static NetworkUserQuery * inst_
Definition: odnetworkaccess.h:177
void message(const char *)
default: to stderr
The generalization of something (e.g. a computation) where the steps must be done in sequence...
Definition: task.h:147
od_ostream * osd_
Definition: odnetworkaccess.h:127
Generalized set of parameters of the keyword-value type.
Definition: iopar.h:53
Class that can execute a task.
Definition: task.h:193
void setHttpProxy(const char *hostname, int port, bool auth=false, const char *username=0, const char *password=0)
const char * sKeyUseProxy()
Definition: odnetworkaccess.h:74
BufferStringSet urls_
Definition: odnetworkaccess.h:123
Resizable buffer of elements.
Definition: databuf.h:19
const char * sKeyProxyPassword()
Definition: odnetworkaccess.h:83
od_int64 nrdone_
Definition: odnetworkaccess.h:131
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:38
bool downloadToBuffer(const char *url, DataBuffer &, uiString &errmsg, TaskRunner *taskr=0)
bool initneeded_
Definition: odnetworkaccess.h:122
bool uploadQuery(const char *url, const IOPar &querypars, uiString &errmsg, TaskRunner *taskr=0, uiString *returnedmessage=0)
od_int64 getFileSize(const char *)
RefMan< Network::HttpRequestProcess > odnr_
Definition: odnetworkaccess.h:160
BufferString url_
Definition: odnetworkaccess.h:156
bool getProxySettingsFromUser()
int nrfilesdownloaded_
Definition: odnetworkaccess.h:125
bool getRemoteFileSize(const char *url, od_int64 &size, uiString &errmsg)
od_int64 totalnr_
Definition: odnetworkaccess.h:132
bool uploadFile(const char *url, const char *localfname, const char *remotefname, const char *ftype, const IOPar &postvars, uiString &errmsg, TaskRunner *taskr=0, uiString *returnedmessage=0)
BufferString header_
Definition: odnetworkaccess.h:157
const DataBuffer & data_
Definition: odnetworkaccess.h:159

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2017