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
238 das_range* pRng, const das_time* tBeg, const das_time* tEnd
239);
240
241
253 das_range* pRng, const char* sCoord, int64_t nBeg, int64_t nEnd
254);
255
256
271 das_range* pRng, const char* sCoord,
272 const das_datum* dmBeg, const das_datum* dmEnd
273);
274
275
276/* ************************************************************************* */
277/* Protocol enumeration */
278
280typedef enum das_uri_proto_e {
281 DURI_PROTO_FILE = 0, /* no prefix, or explicit file:// */
282 DURI_PROTO_HTTP, /* http:// */
283 DURI_PROTO_HTTPS, /* https:// */
285
286
287/* Opaque, defined in uri.c. A level is one path component: a directory name
288 * or the file name. */
289typedef struct das_uri_seg_t DasUriSeg;
290typedef struct das_uri_level_t DasUriLevel;
291
292
293/* ************************************************************************* */
294/* A parsed URI template */
295
296typedef struct das_uri_tplt_t {
297 bool bHasWild; /* true if template contains $x or $v */
298 bool bLiteral; /* true if template contains no coordinate fields; */
299 /* ranges are ignored and one path is yielded */
300 DasUriProto eProto; /* protocol derived from leading scheme, or */
301 /* DURI_PROTO_FILE if no prefix is present */
302 int nSegs; /* number of entries in pSegs */
303 DasUriSeg* pSegs; /* heap-allocated segment array; freed by del_ */
304 int nDefs; /* number of registered coordinate definitions */
305 DasUriSegDef* pDefs; /* deep-copied def array; freed by del_ */
306 char* sBase; /* fixed directory above the first variable */
307 /* component, no trailing separator; "." when the */
308 /* template is relative, "/" when only the root */
309 /* is fixed */
310 int nLevels; /* number of directory + filename levels */
311 DasUriLevel* pLevels; /* level plan built in DasUriTplt_pattern(); */
312 /* freed by del_DasUriTplt() */
313} DasUriTplt;
314
315
316/* ************************************************************************* */
317/* A streaming iterator over a URI template and coordinate ranges */
318
319typedef struct das_uri_iter_t {
320 const DasUriTplt* pTplt;
321 int nRanges;
322 const das_range* pRanges; /* caller owns; must outlive iterator */
323 bool bDone;
324 char sCurrent[DURI_MAX_PATH]; /* path returned by _next() */
325 void* pState; /* scan state, owned by the iterator */
326} DasUriIter;
327
328
329/* ************************************************************************* */
330/* API */
331
346DAS_API const DasUriSegDef* das_time_uridef(void);
347
348
359DAS_API DasUriTplt* new_DasUriTplt(void);
360
361
375DAS_API DasErrCode DasUriTplt_register(DasUriTplt* pThis, const DasUriSegDef* pDef);
376
377
392DAS_API DasErrCode DasUriTplt_pattern(DasUriTplt* pThis, const char* sTemplate);
393
394
398DAS_API void del_DasUriTplt(DasUriTplt* pTplt);
399
400
411DAS_API char* DasUriTplt_toStr(const DasUriTplt* pThis, char* sBuf, size_t uLen);
412
413
438DAS_API DasErrCode init_DasUriIter(
439 DasUriIter* pThis, const DasUriTplt* pTplt,
440 int nRanges, const das_range* pRanges
441);
442
443
450DAS_API void fini_DasUriIter(DasUriIter* pThis);
451
452
467DAS_API DasUriIter* new_DasUriIter(
468 const DasUriTplt* pTplt, int nRanges, const das_range* pRanges
469);
470
471
485DAS_API const char* DasUriIter_next(DasUriIter* pThis);
486
487
491DAS_API void del_DasUriIter(DasUriIter* pThis);
492
493
494/* ************************************************************************* */
495/* Convenience functions */
496
513DAS_API char* DasUriTplt_render(
514 const DasUriTplt* pThis, int nRanges, const das_range* pRanges,
515 char* sBuf, size_t uLen
516);
517
518
550DAS_API char** das_uri_list(
551 const char* sTemplate, const DasUriSegDef* pDef,
552 int nRanges, const das_range* pRanges,
553 size_t* pCount
554);
555
556
557#ifdef __cplusplus
558}
559#endif
560
561#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:189
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:280
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.