1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
|
/**
* VOC_REGISTRYQUERY -- Utility code to act as a client interface to
* the NVO Registry service.
*
* RegistryQuery
* ----------------------
*
* High-Level Query:
*
* res = voc_regSearch (term1, term2, orValues)
*
* Programmatic Query:
*
* query = voc_regQuery (term, orValues) // OR keyword list?
*
* voc_regAddSearchTerm (query, term, orValue) // OR term w/ previous
* voc_regRemoveSearchTerm (query, term) // remove search term
* count = voc_regGetSTCount (query)
*
* str = voc_regGetQueryString (query) // GET form of query
*
* res = voc_regExecute (query) // return result obj
* str = voc_regExecuteRaw (query) // return raw XML
*
* RegistryQueryResult
*
* count = voc_resGetCount (res)
*
* str = voc_resGetStr (res, attribute, index)
* dval = voc_resGetFloat (res, attribute, index)
* ival = voc_resGetInt (res, attribute, index)
*
* For this implementation, we've chose to use the NVO Registry at
* JHU/STScI, specifically the QueryRegistry() method which provides a
* 'SimpleResource' form of the resource record. Support for the newer
* IVOA standard will be added later, for now we can quickly access the most
* commonly used fields of a resource using both a keyword and SQL form of
* the search.
*
*
* @file vocRegistry_spp.c
* @author Michael Fitzpatrick
* @version July 2006
*
*************************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <errno.h>
#define _VOCLIENT_LIB_
#include "VOClient.h"
/* Procedure name mapping.
*/
#ifdef _NO_US_
#define vx_regsearch vxregh
#define vx_regsearchbysvc vxregc
#define vx_regquery vxregy
#define vx_raddsearchterm vxradm
#define vx_rremovesearchterm vxrrem
#define vx_rgetstcount vxrget
#define vx_rgetquerystring vxrgeg
#define vx_rexecute vxrexe
#define vx_rexecuteraw vxrexw
#define vx_rscount vxrsct
#define vx_rsstr vxrssr
#define vx_rsfloat vxrsft
#define vx_rsint vxrsit
#else
#define vx_regsearch vxregh_
#define vx_regsearchbysvc vxregc_
#define vx_regquery vxregy_
#define vx_raddsearchterm vxradm_
#define vx_rremovesearchterm vxrrem_
#define vx_rgetstcount vxrget_
#define vx_rgetquerystring vxrgeg_
#define vx_rexecute vxrexe_
#define vx_rexecuteraw vxrexw_
#define vx_rscount vxrsct_
#define vx_rsstr vxrssr_
#define vx_rsfloat vxrsft_
#define vx_rsint vxrsit_
#endif
extern VOClient *vo; /* Interface runtime struct */
/* SPP Type definitions.
*/
#define XCHAR short
#define PKCHAR char
#define XINT int
#define XEOS NULL
/* Public interface procedures.
*
*/
RegResult vx_regsearch (XCHAR *term1, XCHAR *term2, int *orValues);
RegResult vx_regsearchbysvc (XCHAR *svc, XCHAR *term, int *orValues);
RegQuery vx_regquery (XCHAR *term, int *orValues);
void vx_raddsearchterm (RegQuery *query, XCHAR *term, int *orValue);
void vx_rremovesearchterm (RegQuery *query, XCHAR *term);
int vx_rgetstcount (RegQuery *query);
int vx_rgetquerystring (RegQuery *query, XCHAR *qstring, int *maxch);
RegResult vx_rexecute (RegQuery *query);
int vx_rexecuteraw (RegQuery *query, XCHAR *result, int *maxch);
int vx_rgcount (RegResult *res);
int vx_rgstr (RegResult *res, XCHAR *attribute, int *index,
XCHAR *result, int *maxch);
double vx_rgfloat (RegResult *res, XCHAR *attribute, int *index);
int vx_rgint (RegResult *res, XCHAR *attribute, int *index);
/* Private interface procedures.
*/
extern PKCHAR *spp2c (XCHAR *instr, int maxch);
extern int c2spp (PKCHAR *instr, XCHAR *outstr, int maxch);
extern int spplen (XCHAR *str);
/**
* VX_REGSEARCH -- High-level procedure to form a query and execute it
* immediately. We allow that 'term1' may be a complex SQL WHERE predicate,
* and that 'term2' (or vice versa) is a search-keyword list. The
* 'orValues' applies to the keyword list (if present), otherwise it applies
* to the two search term elements. The default action if two terms are
* specified is to logically AND them.
*
* The thinking here is that one might want SIAP services for Quasars. This
* is easily expressed in an SQL form to get SIAP resources, however a
* Quasar may be known as a QSO, AGN, active-nuclei, etc and so we need a
* easy way to OR the keywords but AND that result with the SQL predicate.
*
* @brief High-level Registry query interface
* @fn res = vx_regsearch (XCHAR *term1, XCHAR *term2, int *orValues)
*
* @param term1 first search term
* @param term2 second search term
* @param orValues logically OR values?
* @returns handle to result object
*/
RegResult
vx_regsearch (XCHAR *term1, XCHAR *term2, int *orValues)
{
char *_term1 = spp2c (term1, spplen (term1));
char *_term2 = spp2c (term2, spplen (term2));
RegResult _result = voc_regSearch (_term1, _term2, *orValues);
free ((char *) _term1);
free ((char *) _term2);
return (_result);
}
/**
* VX_REGSEARCHBYSERVICE -- Search the Registry using a search term and
* constrain by service type.
*
* @brief Search Registry using a search term and service constraint
* @fn res = vx_regsearchbysvc (XCHAR *svc, XCHAR *term, int *orValues)
*
* @param svc service type constraint
* @param term keyword search term
* @param orValues logically OR values?
* @returns handle to result object
*/
RegResult
vx_regsearchbysvc (XCHAR *svc, XCHAR *term, int *orValues)
{
char *_svc = spp2c (svc, spplen (svc));
char *_term = spp2c (term, spplen (term));
RegResult _result = voc_regSearchByService (_svc, _term, *orValues);
free ((char *) _svc);
free ((char *) _term);
return (_result);
}
/**
* VX_REGQUERY -- Get a RegistryQuery object.
*
* @brief Create a RegistryQuery object.
* @fn query = vx_regquery (XCHAR *term, int *orValues)
*
* @param term keyword search term
* @param orValues logically OR values?
* @returns handle to query object
*/
RegQuery
vx_regquery (XCHAR *term, int *orValues)
{
char *_term = spp2c (term, spplen (term));
RegQuery query = voc_regQuery (_term, *orValues);
free ((char *) _term);
return (query);
}
/**
* VX_REGADDSEARCHTERM -- Add a search term (sql predicate or keyword list)
* to the specified query.
*
* @brief Add a search term to the specified query
* @fn vx_raddsearchterm (RegQuery *query, XCHAR *term, int *orValue)
*
* @param query Registry query handle
* @param term keyword search term
* @param orValues logically OR values?
* @returns nothing
*/
void
vx_raddsearchterm (RegQuery *query, XCHAR *term, int *orValue)
{
char *_term = spp2c (term, spplen (term));
(void) voc_regAddSearchTerm (*query, _term, *orValue);
free ((char *) _term);
}
/**
* VX_REMOVESEARCHTERM -- Remove the search term from the query.
*
* @brief Remove a search term to the specified query
* @fn call vx_rremovesearchterm (RegQuery *query, XCHAR *term)
*
* @param query Registry query handle
* @param term keyword search term
* @returns nothing
*/
void
vx_rremovesearchterm (RegQuery *query, XCHAR *term)
{
char *_term = spp2c (term, spplen (term));
(void) voc_regRemoveSearchTerm (*query, _term);
free ((char *) _term);
}
/**
* VX_REGGETSTCOUNT -- Get the number of search terms in the current query.
*
* @brief Get the number of search terms in the current query.
* @fn count = vx_rgetstcount (RegQuery *query)
*
* @param query Registry query handle
* @returns count of search terms
*/
int
vx_rgetstcount (RegQuery *query)
{
return ( voc_regGetSTCount (*query) );
}
/**
* VX_REGGETQUERYSTRING -- Get the current query as an http GET URL.
*
* @brief Get the current query as an http GET URL.
* @fn len = vx_rgetquerystring (RegQuery *query, XCHAR *qstr, int *maxch)
*
* @param query Registry query handle
* @param qstr returned query string
* @param maxch length of query string
* @returns nothing
*/
int
vx_rgetquerystring (RegQuery *query, XCHAR *qstring, int *maxch)
{
char *_qstring = voc_regGetQueryString (*query);
int len = c2spp (_qstring, qstring, *maxch);
free ((char *) _qstring);
return (len);
}
/**
* VX_REGEXECUTE -- Execute the specified query, returning a result object
* code or NULL.
*
* @brief Execute the specified query
* @fn res = vx_rexecute (RegQuery *query)
*
* @param query Registry query handle
* @returns nothing
*/
RegResult
vx_rexecute (RegQuery *query)
{
return ( voc_regExecute (*query) );
}
/**
* VX_REGEXECUTERAW -- Execute the specified query and return the raw
* resulting XML string.
*
* @brief Execute the specified query and return raw result string
* @fn len = vx_rexecuteraw (RegQuery *query, XCHAR *raw, int *maxch)
*
* @param query Registry query handle
* @param raw raw result string
* @param maxch length of result string
* @returns nothing
*/
int
vx_rexecuteraw (RegQuery *query, XCHAR *result, int *maxch)
{
char *_raw = voc_regExecuteRaw (*query);
int len = c2spp (_raw, result, *maxch);
free ((char *) _raw);
return (len);
}
/****************************************************************************/
/********************* RegistryQueryResult Methods ************************/
/****************************************************************************/
/**
* VX_RESGETCOUNT -- Return a count of the number of results records.
*
* @brief Return a count of the number of results records.
* @fn count = vx_rscount (RegResult *res)
*
* @param res Registry result handle
* @returns number of result records
*/
int
vx_rscount (RegResult *res)
{
return ( voc_resGetCount (*res) );
}
/**
* VX_GETSTR -- Get a string-valued attribute from the result resource
* record. Currently recognized real-valued attributes include:
*
* Title Resource title (long version)
* ShortName Short name of Resource
* ServiceURL Service URL (if appropriate)
* ReferenceURL URL to reference about Resource
* Description Text description of resource
* Identifier Standard ivo identifier of resource
* ServiceType Service Type (Cone, Siap, etc)
* Type Resource Type (catalog, survey, etc)
* CoverageSpatial Spatial coverage (STC)
* CoverageTemporal Temporal coverage of data
*
* CoverageSpectral Spectral coverage (csv list of bandpasses)
* ContentLevel Content level (research, EPO, etc -- csv list)
*
* Attribute string are case-insensitive.
*
* @brief Get a string-valued attribute from the result resource record
* @fn len = vx_rsstr (RegResult *res, XCHAR *attr, int *index,
* XCHAR *result, int *maxch)
*
* @param res Registry result handle
* @param attr record attribute
* @param index record index
* @param result attribute string
* @param maxch length of attribute string
* @returns nothing
*/
int
vx_rsstr (RegResult *res, XCHAR *attribute, int *index,
XCHAR *result, int *maxch)
{
char *_attribute = spp2c (attribute, spplen (attribute));
char *_result = voc_resGetStr (*res, _attribute, *index);
int len = c2spp (_result, result, *maxch);
free ((char *) _result);
return (len);
}
/**
* VX_GETFLOAT -- Get a real-valued attribute from the result resource
* record. Currently recognized real-valued attributes include:
*
* MaxSR maximum search radius
*
* Attribute string are case-insensitive.
*
* @brief Get a real-valued attribute from the result resource record
* @fn dval = vx_rsfloat (RegResult *res, XCHAR *attr, int *index)
*
* @param res Registry result handle
* @param attr record attribute
* @param index record index
* @returns double-precision value
*/
double
vx_rsfloat (RegResult *res, XCHAR *attribute, int *index)
{
char *_attribute = spp2c (attribute, spplen (attribute));
double dval = voc_resGetFloat (*res, _attribute, *index);
free ((char *) _attribute);
return (dval);
}
/**
* VX_GETINT -- Get a integer-valued attribute from the result resource
* record. Currently recognized real-valued attributes include:
*
* MaxRecords maximum records returned by the service
*
* Attribute string are case-insensitive.
*
* @brief Get an int-valued attribute from the result resource record
* @fn ival = vx_rsint (RegResult *res, XCHAR *attr, int *index)
*
* @param res Registry result handle
* @param attr record attribute
* @param index record index
* @returns integer value
*/
int
vx_rsint (RegResult *res, XCHAR *attribute, int *index)
{
char *_attribute = spp2c (attribute, spplen (attribute));
int ival = voc_resGetInt (*res, _attribute, *index);
free ((char *) _attribute);
return (ival);
}
|