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

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