das2C
das core C utilities (v3)
Loading...
Searching...
No Matches
uri.h
Go to the documentation of this file.
1/* Copyright (C) 2026 Chris Piker <chris-piker@uiowa.edu>
2 *
3 * This file is part of das2C, the Core Das2 C Library.
4 *
5 * das2C is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU Lesser General Public License version 2.1 as published
7 * by the Free Software Foundation.
8 *
9 * das2C is distributed in the hope that it will be useful, but WITHOUT ANY
10 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * version 2.1 along with das2C; if not, see <http://www.gnu.org/licenses/>.
16 */
17
113#ifndef _das_uri_h_
114#define _das_uri_h_
115
116#include <stdbool.h>
117#include <stdint.h>
118
119#include <das3/defs.h>
120#include <das3/time.h>
121#include <das3/datum.h>
122
123#ifdef __cplusplus
124extern "C" {
125#endif
126
127
128/* ************************************************************************* */
129/* Limits */
130
132#define DURI_MAX_PATH 2048
133
134
135/* ************************************************************************* */
136/* Coordinate segment field and type definitions */
137
145typedef struct das_uri_field_t {
146 char cShort; /* single-char short token, e.g. 'Y'; '\0' if none */
147 char sLong[32]; /* long name, the "year" in $(time.year) */
148 int nWidth; /* rendered field width (zero-padded); 0 = variable */
149 int nMin; /* smallest valid value; names outside nMin..nMax are */
150 int nMax; /* skipped with a warning */
152
153
171typedef struct das_uri_seg_def_t {
172 char sCoord[32]; /* coordinate name, e.g. "time", "sclk", "orbit" */
173 int nFields; /* number of entries in pFields */
174 DasUriField* pFields; /* sub-field table; caller owns until register() */
176
177
178/* ************************************************************************* */
179/* Coordinate query range */
180
202typedef struct das_range_t {
203 char sCoord[32]; /* coordinate or sub-field: "time", "sclk.mod64k" */
204 das_datum dBeg; /* inclusive range begin */
205 das_datum dEnd; /* exclusive range end */
206} das_range;
207
208
209/* ************************************************************************* */
210/* Range initializers */
211
223 das_range* pRng, const char* sBeg, const char* sEnd
224);
225
226
235 das_range* pRng, const das_time* tBeg, const das_time* tEnd
236);
237
238
250 das_range* pRng, const char* sCoord, int64_t nBeg, int64_t nEnd
251);
252
253
268 das_range* pRng, const char* sCoord,
269 const das_datum* dmBeg, const das_datum* dmEnd
270);
271
272
273/* ************************************************************************* */
274/* Protocol enumeration */
275
277typedef enum das_uri_proto_e {
278 DURI_PROTO_FILE = 0, /* no prefix, or explicit file:// */
279 DURI_PROTO_HTTP, /* http:// */
280 DURI_PROTO_HTTPS, /* https:// */
282
283
284/* Opaque, defined in uri.c. A level is one path component: a directory name
285 * or the file name. */
286typedef struct das_uri_seg_t DasUriSeg;
287typedef struct das_uri_level_t DasUriLevel;
288
289
290/* ************************************************************************* */
291/* A parsed URI template */
292
293typedef struct das_uri_tplt_t {
294 bool bHasWild; /* true if template contains $x or $v */
295 bool bLiteral; /* true if template contains no coordinate fields; */
296 /* ranges are ignored and one path is yielded */
297 DasUriProto eProto; /* protocol derived from leading scheme, or */
298 /* DURI_PROTO_FILE if no prefix is present */
299 int nSegs; /* number of entries in pSegs */
300 DasUriSeg* pSegs; /* heap-allocated segment array; freed by del_ */
301 int nDefs; /* number of registered coordinate definitions */
302 DasUriSegDef* pDefs; /* deep-copied def array; freed by del_ */
303 char* sBase; /* fixed directory above the first variable */
304 /* component, no trailing separator; "." when the */
305 /* template is relative, "/" when only the root */
306 /* is fixed */
307 int nLevels; /* number of directory + filename levels */
308 DasUriLevel* pLevels; /* level plan built in DasUriTplt_pattern(); */
309 /* freed by del_DasUriTplt() */
310} DasUriTplt;
311
312
313/* ************************************************************************* */
314/* A streaming iterator over a URI template and coordinate ranges */
315
316typedef struct das_uri_iter_t {
317 const DasUriTplt* pTplt;
318 int nRanges;
319 const das_range* pRanges; /* caller owns; must outlive iterator */
320 bool bDone;
321 char sCurrent[DURI_MAX_PATH]; /* path returned by _next() */
322 void* pState; /* scan state, owned by the iterator */
323} DasUriIter;
324
325
326/* ************************************************************************* */
327/* API */
328
343DAS_API const DasUriSegDef* das_time_uridef(void);
344
345
356DAS_API DasUriTplt* new_DasUriTplt(void);
357
358
372DAS_API DasErrCode DasUriTplt_register(DasUriTplt* pThis, const DasUriSegDef* pDef);
373
374
389DAS_API DasErrCode DasUriTplt_pattern(DasUriTplt* pThis, const char* sTemplate);
390
391
395DAS_API void del_DasUriTplt(DasUriTplt* pTplt);
396
397
407DAS_API char* DasUriTplt_toStr(const DasUriTplt* pThis, char* sBuf, int nLen);
408
409
434DAS_API DasErrCode init_DasUriIter(
435 DasUriIter* pThis, const DasUriTplt* pTplt,
436 int nRanges, const das_range* pRanges
437);
438
439
446DAS_API void fini_DasUriIter(DasUriIter* pThis);
447
448
463DAS_API DasUriIter* new_DasUriIter(
464 const DasUriTplt* pTplt, int nRanges, const das_range* pRanges
465);
466
467
481DAS_API const char* DasUriIter_next(DasUriIter* pThis);
482
483
487DAS_API void del_DasUriIter(DasUriIter* pThis);
488
489
490/* ************************************************************************* */
491/* Convenience functions */
492
509DAS_API char* DasUriTplt_render(
510 const DasUriTplt* pThis, int nRanges, const das_range* pRanges,
511 char* sBuf, int nLen
512);
513
514
546DAS_API char** das_uri_list(
547 const char* sTemplate, const DasUriSegDef* pDef,
548 int nRanges, const das_range* pRanges,
549 size_t* pCount
550);
551
552
553#ifdef __cplusplus
554}
555#endif
556
557#endif /* _das_uri_h_ */
Minimal definitions for das2 utilities that can safely be run without calling das_init().
int DasErrCode
return code type 0 indicates success, negative integer indicates failure
Definition defs.h:184
One sub-field within a named coordinate type.
Definition uri.h:145
Definition of one coordinate type for use by the URI template parser.
Definition uri.h:171
A constraint on one coordinate (or sub-field) used to select matching files.
Definition uri.h:202
Basic date-time structure used throughout the Das1 & Das2 utilities.
Definition time.h:43
Das Time Utilities.
#define DURI_MAX_PATH
Maximum length of a rendered URI / file path.
Definition uri.h:132
DAS_API const DasUriSegDef * das_time_uridef(void)
Return the built-in coordinate definition for the time coordinate.
DAS_API DasErrCode das_range_fromTime(das_range *pRng, const das_time *tBeg, const das_time *tEnd)
Initialize a das_range for the "time" coordinate from das_time structs.
DAS_API DasErrCode das_range_fromUtc(das_range *pRng, const char *sBeg, const char *sEnd)
Initialize a das_range for the "time" coordinate from ISO-8601 UTC strings.
DAS_API DasErrCode das_range_fromDatum(das_range *pRng, const char *sCoord, const das_datum *dmBeg, const das_datum *dmEnd)
Initialize a das_range from pre-built das_datum values.
DasUriProto
Transport protocol, from the leading scheme of a URI template.
Definition uri.h:277
DAS_API char ** das_uri_list(const char *sTemplate, const DasUriSegDef *pDef, int nRanges, const das_range *pRanges, size_t *pCount)
Collect every path a template and ranges yield into one heap array.
DAS_API DasErrCode das_range_fromInt(das_range *pRng, const char *sCoord, int64_t nBeg, int64_t nEnd)
Initialize a das_range for a named integer sub-field.