aboutsummaryrefslogtreecommitdiff
path: root/vo/votools/regdb.cl
blob: 28891d55e5af659aa7b034d4cd60ed3b337d95e8 (plain) (blame)
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
#{ REGDB -- Registry DB utility.

procedure regdb (arg1, arg2, arg3)

string	arg1				{ prompt = "Command/Search Term"     }
string	arg2				{ prompt = "Search Term"	     }
string	arg3				{ prompt = "Optional arg"	     }

string	type     = ""			{ prompt = "Service type constraint" }
string	bandpass = ""			{ prompt = "Bandpass constraint"     }

string	alias    = ""			{ prompt = "Resource alias"	     }
string	ivorn    = ""			{ prompt = "Ivorn string"	     }
string	sname    = ""			{ prompt = "Short Name"	      	     }

string	svctype  = ""			{ prompt = "Resource type"	     }
string	bpass    = ""			{ prompt = "Bandpass"	      	     }
string	url      = ""			{ prompt = "Service URL"	     }
string	desc     = ""			{ prompt = "Description"	     }

bool	verbose  = no			{ prompt = "Print result?"	     }
int	status   = 0			{ prompt = "status code"	     }

begin
    string  tf, t, a, b, i, s, u, d, lterm, cmds = ""
    string  lcmd, lalias, ltype, lbpass, livorn, lsname, ldesc, lresdb, lnew
    bool    verb, found


    # Initialize the command dictionary.
    cmds   = cmds // "|list|resolve|search"
    cmds   = cmds // "|type|alias|bpass|ivorn|sname|url|desc"
    cmds   = cmds // "|add|del|update|rename|"


    if ($nargs == 1 && strdic (arg1, cmds) > 0) {
	# cl> regdb list
	lcmd = arg1
	lterm = ""

    } else if ($nargs == 3 && arg1 == "rename") {
	# cl> regdb rename <old> <new>
	lcmd = arg1
	lterm = ""
	lnew = arg3

    } else if ($nargs == 1 || strdic (arg1, cmds) == 0) {
	# cl> regdb <ivorn> | <alias> | <sname>
	lcmd = "resolve"
	lterm = strlwr (arg1)

    } else if ($nargs > 1 && strdic(arg1,cmds) > 0 && strdic(arg2,cmds) == 0) {
	# cl> regdb list  <ivorn> | <alias> | <sname>
	lcmd = arg1
	lterm = strlwr (arg2)
    } else {
	lcmd = arg1
	lterm = ""
    }

    lalias = strlwr (alias)
    ltype  = strlwr (substr (type,1,1))
    lbpass = strlwr (bandpass)

    lsname = strlwr (sname)
    livorn = strlwr (ivorn)
    lresdb = vo.resdb			# from package param file
    ldesc  = ""
    verb   = verbose

    # Dump the database to a parsable file.
    tf = mktemp ("tmp$tf")
    translit (lresdb, ",", " ") | fields ("STDIN", "1-", > tf)

	
    status = 0

    # Resolve the search term.
    if (lcmd != "list" && lterm != "") {
	found = no
	delete ("uparm$url", verify-, >& "dev$null")
        list = tf
	status = 1
        while (fscan (list, t, a, b, i, s, u, d) != EOF) {

	    if (lterm == strlwr(a) || lterm == strlwr(b) || 
		lterm == strlwr(i) || lterm == strlwr(s)) {

		    if ((lbpass != "" && lbpass != strlwr(b)))
		        next
		    if ((ltype != "" && ltype != strlwr(t)))
		        next

	    	    printf ("%s\n", d) | \
			translit ("STDIN", ":", " ", collapse+) | scan (ldesc)
	            svctype  = t ; alias = a ; bpass = b ; ivorn = i
	            sname = s ; url   = u ; desc  = ldesc
		    print (u, > "uparm$url")
		    found = yes
		    status = 0
		    break;
	    }
        }
        list = ""

	if (found == no) {
	    printf ("Resource '%s' not found\n", lterm)
	    #
	    # FIXME -- Should we call the Registry here for a search????
	    #
	    svctype  = "" ; bpass = "" ; ivorn = "" ; desc  = "" ; url   = ""
	    if (lalias != "") alias = lterm
	    if (lsname != "") sname = lterm
	    status = 1
	    goto done_
	}
	;
    }


    if (lcmd == "list") {				# LIST
        list = tf
	while (fscan (list, t, a, b, i, s, u, d) != EOF) {

	    if (lterm == "") {
		# cl> regdb list bandpass=optical
	        if (ltype != "" && ltype != strlwr(t))
		     next
	        if (lbpass != "" && strstr (lbpass, strlwr(b)) == 0)
		     next

	        printf ("%-10s  ", a)
	        printf ("%s  ", t)
	        if (lbpass == "") printf ("%-8s  ", b)
	        printf ("%s\n", d) | translit ("STDIN", ":", " ", collapse+)

	    } else {
		# cl> regdb list  <ivorn> | <alias> | <sname>

	        if (lterm == strlwr(a) || lterm == strlwr(b) || 
		    lterm == strlwr(i) || lterm == strlwr(s)) {
	        	printf ("     Alias: %s\n", a)
	        	printf (" ShortName: %s\n", s)
	        	printf ("     Title: %s\n", d)
	        	printf ("      Type: %s\n", t)
	        	printf ("  Bandpass: %s\n", b)
	        	printf ("     Ivorn: %s\n", i)
	        	printf ("    SvcURL: %s\n", u)
		        #break;
		}
	    }
	}
        list = ""

    } else if (lcmd == "type") {			# TYPE
	print (t)

    } else if (lcmd == "alias") {			# ALIAS
	if (lterm != "") {
	    print (a)
	} else {
            list = tf
	    while (fscan (list, t, a, b, i, s, u, d) != EOF) {
	        if ((lalias!="" && lalias == strlwr(a)) ||
		    (ldesc !="" && ldesc == strlwr(d))  ||
		    (livorn!="" && livorn == strlwr(i)) ||
	            (ltype != "" && ltype == strlwr(t))   ||
	            (lbpass != "" && lbpass == strlwr(b)) ||
		    (lsname!="" && lsname == strlwr(s)) ) {

			if (verbose)
	        	    print (a)
			else
			    alias = a
		}
	    }
            list = ""
	}
	svctype  = "" ; bpass = "" ; ivorn = "" ; desc  = "" ; url   = ""
	alias    = "" ; sname = ""
    } else if (lcmd == "bpass") {			# BPASS
	if (lterm != "") {
	    print (b)
	} else {
            list = tf
	    while (fscan (list, t, a, b, i, s, u, d) != EOF) {
	        if ((lalias!="" && lalias == strlwr(a)) ||
		    (ldesc !="" && ldesc == strlwr(d))  ||
		    (livorn!="" && livorn == strlwr(i)) ||
	            (ltype != "" && ltype == strlwr(t))   ||
	            (lbpass != "" && lbpass == strlwr(b)) ||
		    (lsname!="" && lsname == strlwr(s)) ) {

			if (verbose)
	        	    print (b)
			else
			    bpass = b
		}
	    }
            list = ""
	}
	svctype  = "" ; bpass = "" ; ivorn = "" ; desc  = "" ; url   = ""
	alias    = "" ; sname = ""
    } else if (lcmd == "ivorn") {			# IVORN
	if (lterm != "") {
	    print (i)
	} else {
            list = tf
	    while (fscan (list, t, a, b, i, s, u, d) != EOF) {
	        if ((lalias!="" && lalias == strlwr(a)) ||
		    (ldesc !="" && ldesc == strlwr(d))  ||
		    (livorn!="" && livorn == strlwr(i)) ||
	            (ltype != "" && ltype == strlwr(t))   ||
	            (lbpass != "" && lbpass == strlwr(b)) ||
		    (lsname!="" && lsname == strlwr(s)) ) {

			if (verbose)
	        	    print (i)
			else
			    ivorn = i
		}
	    }
            list = ""
	}
	svctype  = "" ; bpass = "" ; ivorn = "" ; desc  = "" ; url   = ""
	alias    = "" ; sname = ""
    } else if (lcmd == "sname") {			# SNAME
	if (lterm != "") {
	    print (s)
	} else {
            list = tf
	    while (fscan (list, t, a, b, i, s, u, d) != EOF) {
	        if ((lalias!="" && lalias == strlwr(a)) ||
		    (ldesc !="" && ldesc == strlwr(d))  ||
		    (livorn!="" && livorn == strlwr(i)) ||
	            (ltype != "" && ltype == strlwr(t))   ||
	            (lbpass != "" && lbpass == strlwr(b)) ||
		    (lsname!="" && lsname == strlwr(s)) ) {

			if (verbose)
	        	    print (s)
			else
			    sname = s
		}
	    }
            list = ""
	}
	svctype  = "" ; bpass = "" ; ivorn = "" ; desc  = "" ; url   = ""
	alias    = "" ; sname = ""
    } else if (lcmd == "url") {				# URL
	if (lterm != "") {
	    print (u)
	} else {
            list = tf
	    while (fscan (list, t, a, b, i, s, u, d) != EOF) {
	        if ((lalias!="" && lalias == strlwr(a)) ||
		    (ldesc !="" && ldesc == strlwr(d))  ||
		    (livorn!="" && livorn == strlwr(i)) ||
	            (ltype != "" && ltype == strlwr(t))   ||
	            (lbpass != "" && lbpass == strlwr(b)) ||
		    (lsname!="" && lsname == strlwr(s)) ) {

			if (verbose)
	        	    print (u)
			else
			    url = u
		}
	    }
            list = ""
	}
	svctype  = "" ; bpass = "" ; ivorn = "" ; desc  = "" ; url   = ""
	alias    = "" ; sname = ""
    } else if (lcmd == "desc") {			# DESCRIPTION
	if (lterm != "") {
	    print (d)
	} else {
            list = tf
	    while (fscan (list, t, a, b, i, s, u, d) != EOF) {
	        if ((lalias!="" && lalias == strlwr(a)) ||
		    (ldesc !="" && ldesc == strlwr(d))  ||
		    (livorn!="" && livorn == strlwr(i)) ||
	            (ltype != "" && ltype == strlwr(t))   ||
	            (lbpass != "" && lbpass == strlwr(b)) ||
		    (lsname!="" && lsname == strlwr(s)) ) {

			if (verbose)
	        	    print (d)
		}
	    }
            list = ""
	}
	svctype  = "" ; bpass = "" ; ivorn = "" ; desc  = "" ; url   = ""
	alias    = "" ; sname = ""


    } else if (lcmd == "add") {				# ADD TO DB

    } else if (lcmd == "del") {				# DELETE FROM DN

    } else if (lcmd == "update") {			# UPDATE DB

    } else if (lcmd == "rename") {			# RENAME ALIAS
	# Need arg3


    } else if (lcmd == "resolve" || lcmd == "search") {	# RESOLVE
        list = tf
 	status = 1
	while (fscan (list, t, a, b, i, s, u, d) != EOF) {
	    if ((lalias != "" && lalias == strlwr(a)) ||
		(lterm != "" && lterm == strlwr(a))   ||
		(ldesc != "" && ldesc == strlwr(d))   ||
		(livorn != "" && livorn == strlwr(i)) ||
		(lterm == "") ||
		(lsname!="" && lsname == strlwr(s)) ) {

	            if ((ltype != "" && ltype != strlwr(t)) ||
	                (lbpass != "" && lbpass != strlwr(b)) ) 
		    	    next

	    	    printf ("%s\n", d) | \
			translit ("STDIN", ":", " ", collapse+) | scan (ldesc)
	            svctype  = t ; alias = a ; bpass = b ; ivorn = i
	            sname = s ; url   = u ; desc  = ldesc
		    status = 0
		    break
	    }
	}
        list = ""

    } else {
	printf ("Command '%s' not found\n", lcmd)
	status = 1
    }

done_:
    type = ""
    bandpass = ""

    del (tf, verify-)
end