1 /*===========================================================================
2 *
3 *                            Public Domain Notice
4 *               National Center for Biotechnology Information
5 *
6 *  This software/database is a "United States Government Work" under the
7 *  terms of the United States Copyright Act.  It was written as part of
8 *  the author's official duties as a United States Government employee and
9 *  thus cannot be copyrighted.  This software/database is freely available
10 *  to the public for use. The National Library of Medicine and the U.S.
11 *  Government have not placed any restriction on its use or reproduction.
12 *
13 *  Although all reasonable efforts have been taken to ensure the accuracy
14 *  and reliability of the software and data, the NLM and the U.S.
15 *  Government do not and cannot warrant the performance or results that
16 *  may be obtained by using this software or data. The NLM and the U.S.
17 *  Government disclaim all warranties, express or implied, including
18 *  warranties of performance, merchantability or fitness for any particular
19 *  purpose.
20 *
21 *  Please cite the author in any work or product based on this material.
22 *
23 * ===========================================================================
24 *
25 */
26 
27 #ifndef _h_path_priv_
28 #define _h_path_priv_
29 
30 #ifndef _h_vfs_extern_
31 #include <vfs/extern.h>
32 #endif
33 
34 #ifndef _h_klib_refcount_
35 #include <klib/refcount.h>
36 #endif
37 
38 #ifndef _h_klib_data_buffer_
39 #include <klib/data-buffer.h>
40 #endif
41 
42 #ifndef _h_klib_text_
43 #include <klib/text.h>
44 #endif
45 
46 #ifndef _h_vdb_quality_
47 #include <vdb/quality.h> /* VQuality */
48 #endif
49 
50 #ifndef _h_vfs_path_
51 #include <vfs/path.h>
52 #endif
53 
54 #ifndef _h_vfs_resolver_
55 #include <vfs/resolver.h> /* VRemoteProtocols */
56 #endif
57 
58 #ifdef __cplusplus
59 extern "C" {
60 #endif
61 
62 struct KSrvError;
63 
64 /* VPath Type: -----------------------------------------------------------------
65  * how many extended properties ( from name resolver response ) are initialized
66  */
67 typedef enum {
68     eVPnoExt,  /* does not have extended part */
69     eVPWithId, /* has object-id */
70     eVPext,    /* has all extanded properties */
71 } EVPathType;
72 typedef enum {
73     eSCundefined,
74     eSCrun,
75     eSCpileup,
76     eSCrealign,
77     eSCvdbcache,
78 } ESraClass;
79 /*
80 * VPath
81 */
82 struct VPath
83 {
84     KDataBuffer data;
85 
86     String scheme;
87     String auth;
88     String host;
89     String portname;
90     String path;
91     String query;
92     String fragment;
93 
94     KRefcount refcount;
95 
96     uint32_t obj_id;
97     uint32_t acc_code;
98 
99     uint32_t ipv4;
100     uint16_t ipv6 [ 8 ];
101     uint16_t portnum;
102 
103     uint8_t scheme_type;
104     uint8_t host_type;
105     uint8_t path_type;
106 
107     bool from_uri;
108     bool missing_port;
109     bool highly_reliable;
110 
111     ESraClass sraClass; /* type of SRA file: undefined, run, pileup etc */
112 
113     /* how many extended properties ( from name resolver response )
114        are initialized */
115     EVPathType ext;
116 
117     String     id;           /* object-id */
118 
119     String     tick;         /* dbGaP download ticket */
120     uint64_t   osize;        /* object's un-encrypted size in bytes */
121     KTime_t    modification; /* object's modification date. 0 if unknown */
122     KTime_t    expiration;   /* expiration date of this VPath object.
123                                 0 if infinite */
124 
125     int64_t    projectId;    /* dbGaP project Id:
126                                 <0 (not set): public URL
127                                 >=0 (vaoid values): protected URL
128                                     N.B. 0 is a valid dbGaP project Id */
129 
130     uint8_t    md5 [ 16 ];  /* md5 checksum object's un-encrypted if known */
131     bool       has_md5;
132 
133     String     service;      /* s3, gs, sra-ncbi, ftp-ncbi, sra-sos, etc. */
134     String     objectType;
135     String     type;
136     String     acc;
137 
138     String     name;
139     String     nameExtension; /* file extension in name. don't free */
140 
141     const VPath * vdbcache;
142     bool          vdbcacheChecked; /* no need to check vdbcache URL when
143                                   vdbcacheChecked = true and vdbcache == NULL */
144 
145     bool       ceRequired;
146     bool       payRequired;
147 
148     const String * accOfParentDb; /* for refseqs */
149 
150     bool magic; /* was created from magic env.var. */
151 
152     /* version of names service returned this VPath: 3.0 or SDL ... */
153     uint32_t version;
154 
155     VQuality quality;
156 };
157 
158 enum VPathVariant
159 {
160     vpInvalid,
161     vpOID,
162     vpAccession,
163     vpNameOrOID,
164     vpNameOrAccession,
165     vpName,
166     vpRelPath,
167     vpUNCPath,
168     vpFullPath,
169     vpAuth,
170     vpHostName,
171     vpEndpoint
172 };
173 
174 enum VHostVariant
175 {
176     vhDNSName,
177     vhIPv4,
178     vhIPv6
179 };
180 
181 /* legacy support */
182 #define VPathMake LegacyVPathMake
183 VFS_EXTERN rc_t VPathMake ( VPath ** new_path, const char * posix_path );
184 #define VPathMakeFmt LegacyVPathMakeFmt
185 rc_t VPathMakeFmt ( VPath ** new_path, const char * fmt, ... );
186 #define VPathMakeVFmt LegacyVPathMakeVFmt
187 rc_t VPathMakeVFmt ( VPath ** new_path, const char * fmt, va_list args );
188 VFS_EXTERN rc_t LegacyVPathMakeSysPath ( VPath ** new_path, const char * sys_path );
189 
190 typedef enum eVPUri_t
191 {
192     vpuri_invalid = -1,
193     vpuri_none,
194     vpuri_not_supported,
195     vpuri_ncbi_file,
196     vpuri_ncbi_vfs = vpuri_ncbi_file,
197     vpuri_file,
198     vpuri_ncbi_acc,
199     vpuri_http,
200     vpuri_https,
201     vpuri_ftp,
202     vpuri_ncbi_legrefseq,
203     vpuri_ncbi_obj,     /* for dbGaP objects */
204     vpuri_fasp,         /* for Aspera downloads */
205     vpuri_s3,
206     vpuri_azure,
207     vpuri_google,
208     vpuri_scp,
209     vpuri_sftp,
210     vpuri_count
211 } VPUri_t;
212 
213 #define VPathGetScheme_t LegacyVPathGetScheme_t
214 VFS_EXTERN rc_t CC VPathGetScheme_t ( const VPath * self, VPUri_t * uri_type );
215 
216 #define VPathGetUri_t LegacyVPathGetUri_t
217 VPUri_t VPathGetUri_t (const VPath * self);
218 
219 /* returns true when VPath is protected */
220 bool VPathGetProjectId(const VPath * self, uint32_t * projectId);
221 
222 /* projectId:
223  *  <0  : pubkic URL
224  *  >=0 : protected URL
225  *      N.B. 0 is a valid protected project Id
226  *
227  * version: version of names service that returned this URL
228  */
229 rc_t VPathMakeFromUrl ( VPath ** new_path, const String * url,
230     const String * tick, bool ext, const String * id, uint64_t osize,
231     KTime_t date, const uint8_t md5 [ 16 ], KTime_t exp_date,
232     const char * service, const String * objectType, const String * type,
233     bool ceRequired, bool payRequired, const char * name,
234     int64_t projectId, uint32_t version, const String * acc );
235 
236 rc_t VPathAttachVdbcache(VPath * self, const VPath * vdbcache);
237 
238 rc_t VPathSetId(VPath * self, const String * id);
239 rc_t VPathSetMagic(VPath * self, bool magic);
240 
241 /* Equal
242  *  compares two VPath-s
243  *
244  * "notequal" [ OUT ] - is set
245  *  to union of bits corresponding to difference in different VPath properties
246  *
247  *  returns non-0 rc after a failed call to get property from any of VPath-s
248  */
249 rc_t VPathEqual ( const VPath * l, const VPath * r, int * notequal );
250 /* Close
251  *  compares two VPath-s
252  *  difference between expirations should be withing expirationRange */
253 rc_t VPathClose ( const VPath * l, const VPath * r, int * notequal,
254                   KTime_t expirationRange );
255 
256 rc_t VPathGetAccession(const VPath * self, String * acc);
257 
258 rc_t VPathSetQuality(VPath * self, VQuality quality);
259 rc_t VPathLoadQuality(VPath * self);
260 
261 
262 /***** VPathSet - set of VPath's - genetated from name resolver response ******/
263 
264 typedef struct VPathSet VPathSet;
265 
266 rc_t VPathSetRelease ( const VPathSet * self );
267 rc_t VPathSetGet ( const VPathSet * self, VRemoteProtocols protocols,
268     const struct VPath ** path, const struct VPath ** vdbcache );
269 rc_t VPathSetGetCache ( const VPathSet * self, const struct VPath ** path );
270 rc_t VPathSetGetLocal ( const VPathSet * self, const struct VPath ** path );
271 
272 /* name resolver response row converted into VDB objects */
273 typedef struct {          /*       vdbcache */
274     struct VPath * fasp ; struct VPath * vcFasp;
275     struct VPath * file ; struct VPath * vcFile;
276     struct VPath * http ; struct VPath * vcHttp;
277     struct VPath * https; struct VPath * vcHttps;
278     struct VPath * s3   ; struct VPath * vcS3;
279 
280     struct VPath * mapping  ; /* run/file mapping */
281     struct VPath * vcMapping; /* vdbcache mapping */
282 
283     const struct KSrvError * error;
284     char * reqId;
285     char * respId;
286     uint64_t osize; /*size of VPath object */
287 } EVPath;
288 
289 rc_t VPathSetMake
290     ( VPathSet ** self, const EVPath * src, bool singleUrl );
291 
292 rc_t VPathSetMakeQuery ( VPathSet ** self, const VPath * local, rc_t localRc,
293                          const VPath * cache, rc_t cacheRc );
294 
295 rc_t KSrvErrorMake4(const struct KSrvError ** self,
296                     rc_t rc, uint32_t code, const char * msg);
297 
298 
299 #ifdef __cplusplus
300 }
301 #endif
302 
303 #endif /* _h_path_priv_ */
304 
305 #if 0
306 /******************************** KSrvResponse ********************************/
307 rc_t KSrvResponseRelease ( const KSrvResponse * self );
308 uint32_t KSrvResponseLength ( const KSrvResponse * self );
309 /******************************************************************************/
310 #endif
311