alexandria-zoom 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/ChangeLog +178 -0
- data/LICENSE +504 -0
- data/README.md +94 -0
- data/ext/zoom/extconf.rb +19 -0
- data/ext/zoom/rbzoom.c +34 -0
- data/ext/zoom/rbzoom.h +68 -0
- data/ext/zoom/rbzoomconnection.c +346 -0
- data/ext/zoom/rbzoomoptions.c +121 -0
- data/ext/zoom/rbzoompackage.c +200 -0
- data/ext/zoom/rbzoomquery.c +125 -0
- data/ext/zoom/rbzoomrecord.c +192 -0
- data/ext/zoom/rbzoomresultset.c +268 -0
- data/sample/hello.rb +8 -0
- data/sample/needle.rb +125 -0
- metadata +146 -0
@@ -0,0 +1,200 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2007 Katipo Communications, Ltd.
|
3
|
+
*
|
4
|
+
* This library is free software; you can redistribute it and/or
|
5
|
+
* modify it under the terms of the GNU Lesser General Public
|
6
|
+
* License as published by the Free Software Foundation; either
|
7
|
+
* version 2.1 of the License, or (at your option) any later version.
|
8
|
+
*
|
9
|
+
* This library is distributed in the hope that it will be useful,
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
* Lesser General Public License for more details.
|
13
|
+
*
|
14
|
+
* You should have received a copy of the GNU Lesser General Public
|
15
|
+
* License along with this library; if not, write to the Free Software
|
16
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include "rbzoom.h"
|
20
|
+
#include <stdio.h>
|
21
|
+
|
22
|
+
#ifdef MAKING_RDOC_HAPPY
|
23
|
+
mZoom = rb_define_module("ZOOM");
|
24
|
+
#endif
|
25
|
+
|
26
|
+
/* Document-class: ZOOM::Package
|
27
|
+
*
|
28
|
+
* This class represents an Extended Services Package: an instruction to the server
|
29
|
+
* to do something not covered by the core parts of the Z39.50 standard
|
30
|
+
*/
|
31
|
+
static VALUE cZoomPackage;
|
32
|
+
|
33
|
+
|
34
|
+
static ZOOM_package
|
35
|
+
rbz_package_get (VALUE obj)
|
36
|
+
{
|
37
|
+
ZOOM_package package;
|
38
|
+
|
39
|
+
if (cZoomPackage == Qnil)
|
40
|
+
rb_raise(rb_eRuntimeError, "cZoomPackage is nil: has destroy() already been called on this Package?");
|
41
|
+
|
42
|
+
Data_Get_Struct (obj, struct ZOOM_package_p, package);
|
43
|
+
assert (package != NULL);
|
44
|
+
|
45
|
+
return package;
|
46
|
+
}
|
47
|
+
|
48
|
+
|
49
|
+
/*
|
50
|
+
* call-seq:
|
51
|
+
* make(connection, options)
|
52
|
+
*
|
53
|
+
* Creates a ZOOM::Package from the connection and options specified.
|
54
|
+
*
|
55
|
+
* Returns: the created ZOOM::Package or Qnil.
|
56
|
+
*/
|
57
|
+
VALUE
|
58
|
+
rbz_package_make (ZOOM_connection connection, ZOOM_options options)
|
59
|
+
{
|
60
|
+
|
61
|
+
ZOOM_package package;
|
62
|
+
|
63
|
+
package = ZOOM_connection_package(connection, options);
|
64
|
+
|
65
|
+
if (cZoomPackage == Qnil)
|
66
|
+
rb_raise(rb_eRuntimeError, "cZoomPackage is nil: has destroy() already been called on this Package?");
|
67
|
+
|
68
|
+
return package != NULL
|
69
|
+
? Data_Wrap_Struct (cZoomPackage,
|
70
|
+
NULL,
|
71
|
+
ZOOM_package_destroy,
|
72
|
+
package)
|
73
|
+
: Qnil;
|
74
|
+
}
|
75
|
+
|
76
|
+
|
77
|
+
/*
|
78
|
+
* call-seq:
|
79
|
+
* set_option(key, value)
|
80
|
+
*
|
81
|
+
* key: the name of the option, as a string.
|
82
|
+
*
|
83
|
+
* value: the value of this option (as a string, integer or boolean).
|
84
|
+
*
|
85
|
+
* Sets an option on the package.
|
86
|
+
*
|
87
|
+
* Returns: self.
|
88
|
+
*/
|
89
|
+
static VALUE
|
90
|
+
rbz_package_set_option (VALUE self, VALUE key, VALUE val)
|
91
|
+
{
|
92
|
+
|
93
|
+
ZOOM_package package;
|
94
|
+
|
95
|
+
package = rbz_package_get (self);
|
96
|
+
ZOOM_package_option_set (package,
|
97
|
+
RVAL2CSTR (key),
|
98
|
+
RVAL2CSTR (rb_obj_as_string (val)));
|
99
|
+
|
100
|
+
return self;
|
101
|
+
}
|
102
|
+
|
103
|
+
|
104
|
+
/*
|
105
|
+
* call-seq:
|
106
|
+
* get_option(key)
|
107
|
+
*
|
108
|
+
* key: the name of the option, as a string.
|
109
|
+
*
|
110
|
+
* Gets the value of a package's option.
|
111
|
+
*
|
112
|
+
* Returns: the value of the given option, as a string, integer or boolean.
|
113
|
+
*/
|
114
|
+
static VALUE
|
115
|
+
rbz_package_get_option (VALUE self, VALUE key)
|
116
|
+
{
|
117
|
+
ZOOM_package package;
|
118
|
+
const char *value;
|
119
|
+
|
120
|
+
package = rbz_package_get (self);
|
121
|
+
|
122
|
+
value = ZOOM_package_option_get (package,
|
123
|
+
RVAL2CSTR (key));
|
124
|
+
|
125
|
+
return zoom_option_value_to_ruby_value (value);
|
126
|
+
}
|
127
|
+
|
128
|
+
/*
|
129
|
+
* call-seq:
|
130
|
+
* send(type)
|
131
|
+
*
|
132
|
+
* type: the actual extended service package type to be sent, as a string.
|
133
|
+
*
|
134
|
+
* Sends the package.
|
135
|
+
*
|
136
|
+
* Returns: self.
|
137
|
+
*/
|
138
|
+
static VALUE
|
139
|
+
rbz_package_send(VALUE self, VALUE type)
|
140
|
+
{
|
141
|
+
ZOOM_package package;
|
142
|
+
const char *typeChar;
|
143
|
+
|
144
|
+
package = rbz_package_get (self);
|
145
|
+
|
146
|
+
typeChar = StringValuePtr(type);
|
147
|
+
ZOOM_package_send(package, typeChar);
|
148
|
+
|
149
|
+
return self;
|
150
|
+
}
|
151
|
+
|
152
|
+
|
153
|
+
|
154
|
+
/* Interface to a subset of the Z39.50 extended services.
|
155
|
+
*/
|
156
|
+
void
|
157
|
+
Init_zoom_package (VALUE mZoom)
|
158
|
+
{
|
159
|
+
VALUE c;
|
160
|
+
|
161
|
+
c = rb_define_class_under (mZoom, "Package", rb_cObject);
|
162
|
+
rb_undef_alloc_func(c);
|
163
|
+
|
164
|
+
/* Remove the default constructor to force initialization through Connection#package. */
|
165
|
+
rb_undef_method (CLASS_OF (c), "new");
|
166
|
+
|
167
|
+
/* Instance methods */
|
168
|
+
rb_define_method (c, "set_option", rbz_package_set_option, 2);
|
169
|
+
rb_define_method (c, "get_option", rbz_package_get_option, 1);
|
170
|
+
rb_define_method (c, "send", rbz_package_send, 1);
|
171
|
+
|
172
|
+
// Common Options
|
173
|
+
define_zoom_option (c, "package-name");
|
174
|
+
define_zoom_option (c, "user-id");
|
175
|
+
define_zoom_option (c, "function");
|
176
|
+
define_zoom_option (c, "waitAction");
|
177
|
+
define_zoom_option (c, "targetReference");
|
178
|
+
|
179
|
+
// Item Order, type must be set to itemorder in ZOOM_package_send.
|
180
|
+
define_zoom_option (c, "contact-name");
|
181
|
+
define_zoom_option (c, "contact-phone");
|
182
|
+
define_zoom_option (c, "contact-email");
|
183
|
+
define_zoom_option (c, "itemorder-item");
|
184
|
+
|
185
|
+
// Record Update, type must be set to update in ZOOM_package_send.
|
186
|
+
define_zoom_option (c, "action");
|
187
|
+
define_zoom_option (c, "recordIdOpaque");
|
188
|
+
define_zoom_option (c, "recordIdNumber");
|
189
|
+
define_zoom_option (c, "record");
|
190
|
+
define_zoom_option (c, "syntax");
|
191
|
+
define_zoom_option (c, "databaseName");
|
192
|
+
define_zoom_option (c, "correlationInfo.note");
|
193
|
+
define_zoom_option (c, "correlationInfo.id");
|
194
|
+
define_zoom_option (c, "elementSetName");
|
195
|
+
|
196
|
+
// Database Create, type must be set to create in ZOOM_package_send.
|
197
|
+
// Database Drop, type must be set to drop in ZOOM_package_send.
|
198
|
+
|
199
|
+
cZoomPackage = c;
|
200
|
+
}
|
@@ -0,0 +1,125 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2005 Laurent Sansonetti <lrz@chopine.be>
|
3
|
+
*
|
4
|
+
* This library is free software; you can redistribute it and/or
|
5
|
+
* modify it under the terms of the GNU Lesser General Public
|
6
|
+
* License as published by the Free Software Foundation; either
|
7
|
+
* version 2.1 of the License, or (at your option) any later version.
|
8
|
+
*
|
9
|
+
* This library is distributed in the hope that it will be useful,
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
* Lesser General Public License for more details.
|
13
|
+
*
|
14
|
+
* You should have received a copy of the GNU Lesser General Public
|
15
|
+
* License along with this library; if not, write to the Free Software
|
16
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include "rbzoom.h"
|
20
|
+
|
21
|
+
#ifdef MAKING_RDOC_HAPPY
|
22
|
+
mZoom = rb_define_module("ZOOM");
|
23
|
+
#endif
|
24
|
+
|
25
|
+
/* Class: ZOOM::Query
|
26
|
+
* Search queries.
|
27
|
+
*/
|
28
|
+
static VALUE cZoomQuery;
|
29
|
+
|
30
|
+
static VALUE
|
31
|
+
rbz_query_make (ZOOM_query query)
|
32
|
+
{
|
33
|
+
return query != NULL
|
34
|
+
? Data_Wrap_Struct (cZoomQuery,
|
35
|
+
NULL,
|
36
|
+
ZOOM_query_destroy,
|
37
|
+
query)
|
38
|
+
: Qnil;
|
39
|
+
}
|
40
|
+
|
41
|
+
ZOOM_query
|
42
|
+
rbz_query_get (VALUE obj)
|
43
|
+
{
|
44
|
+
ZOOM_query query;
|
45
|
+
|
46
|
+
Data_Get_Struct (obj, struct ZOOM_query_p, query);
|
47
|
+
assert (query != NULL);
|
48
|
+
|
49
|
+
return query;
|
50
|
+
}
|
51
|
+
|
52
|
+
/*
|
53
|
+
* call-seq: new_prefix(prefix)
|
54
|
+
*
|
55
|
+
* prefix: PQF notation.
|
56
|
+
*
|
57
|
+
* Creates a RPN query using the given PQF notation.
|
58
|
+
*
|
59
|
+
* Returns: a newly created ZOOM::Query object.
|
60
|
+
*/
|
61
|
+
static VALUE
|
62
|
+
rbz_query_new_prefix (VALUE self, VALUE prefix)
|
63
|
+
{
|
64
|
+
ZOOM_query query;
|
65
|
+
|
66
|
+
query = ZOOM_query_create ();
|
67
|
+
ZOOM_query_prefix (query, RVAL2CSTR (prefix));
|
68
|
+
|
69
|
+
return rbz_query_make (query);
|
70
|
+
}
|
71
|
+
|
72
|
+
/* call-seq:
|
73
|
+
* new_cql(prefix)
|
74
|
+
*
|
75
|
+
* prefix: CQL notation.
|
76
|
+
*
|
77
|
+
* Creates a CQL query using the given CQL notation.
|
78
|
+
*
|
79
|
+
* Returns: a newly created ZOOM::Query object.
|
80
|
+
*/
|
81
|
+
static VALUE
|
82
|
+
rbz_query_new_cql (VALUE self, VALUE cql)
|
83
|
+
{
|
84
|
+
ZOOM_query query;
|
85
|
+
|
86
|
+
query = ZOOM_query_create ();
|
87
|
+
ZOOM_query_cql (query, RVAL2CSTR (cql));
|
88
|
+
|
89
|
+
return rbz_query_make (query);
|
90
|
+
}
|
91
|
+
|
92
|
+
/*
|
93
|
+
* call-seq: new_sort_by(criteria)
|
94
|
+
*
|
95
|
+
* criteria: a sort criteria.
|
96
|
+
*
|
97
|
+
* Creates a sort query from the YAZ sorting notation.
|
98
|
+
*
|
99
|
+
* Returns: a newly created ZOOM::Query object.
|
100
|
+
*/
|
101
|
+
static VALUE
|
102
|
+
rbz_query_new_sort_by (VALUE self, VALUE criteria)
|
103
|
+
{
|
104
|
+
ZOOM_query query;
|
105
|
+
|
106
|
+
query = ZOOM_query_create ();
|
107
|
+
ZOOM_query_sortby (rbz_query_get (self), RVAL2CSTR (criteria));
|
108
|
+
|
109
|
+
return rbz_query_make (query);
|
110
|
+
}
|
111
|
+
|
112
|
+
void
|
113
|
+
Init_zoom_query (VALUE mZoom)
|
114
|
+
{
|
115
|
+
VALUE c;
|
116
|
+
|
117
|
+
c = rb_define_class_under (mZoom, "Query", rb_cObject);
|
118
|
+
rb_undef_alloc_func(c);
|
119
|
+
|
120
|
+
rb_define_singleton_method (c, "new_prefix", rbz_query_new_prefix, 1);
|
121
|
+
rb_define_singleton_method (c, "new_cql", rbz_query_new_cql, 1);
|
122
|
+
rb_define_singleton_method (c, "new_sort_by", rbz_query_new_sort_by, 1);
|
123
|
+
|
124
|
+
cZoomQuery = c;
|
125
|
+
}
|
@@ -0,0 +1,192 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2005 Laurent Sansonetti <lrz@chopine.be>
|
3
|
+
*
|
4
|
+
* This library is free software; you can redistribute it and/or
|
5
|
+
* modify it under the terms of the GNU Lesser General Public
|
6
|
+
* License as published by the Free Software Foundation; either
|
7
|
+
* version 2.1 of the License, or (at your option) any later version.
|
8
|
+
*
|
9
|
+
* This library is distributed in the hope that it will be useful,
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
12
|
+
* Lesser General Public License for more details.
|
13
|
+
*
|
14
|
+
* You should have received a copy of the GNU Lesser General Public
|
15
|
+
* License along with this library; if not, write to the Free Software
|
16
|
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
17
|
+
*/
|
18
|
+
|
19
|
+
#include "rbzoom.h"
|
20
|
+
|
21
|
+
#ifdef MAKING_RDOC_HAPPY
|
22
|
+
mZoom = rb_define_module("ZOOM");
|
23
|
+
#endif
|
24
|
+
|
25
|
+
|
26
|
+
/*
|
27
|
+
* A record object is a retrieval record on the client side - created from
|
28
|
+
* result sets.
|
29
|
+
*/
|
30
|
+
static VALUE cZoomRecord;
|
31
|
+
|
32
|
+
VALUE
|
33
|
+
rbz_record_make (ZOOM_record record)
|
34
|
+
{
|
35
|
+
return record != NULL
|
36
|
+
? Data_Wrap_Struct (cZoomRecord,
|
37
|
+
NULL,
|
38
|
+
ZOOM_record_destroy,
|
39
|
+
record)
|
40
|
+
: Qnil;
|
41
|
+
}
|
42
|
+
|
43
|
+
static ZOOM_record
|
44
|
+
rbz_record_get (VALUE obj)
|
45
|
+
{
|
46
|
+
ZOOM_record record;
|
47
|
+
|
48
|
+
Data_Get_Struct (obj, struct ZOOM_record_p, record);
|
49
|
+
assert (record != NULL);
|
50
|
+
|
51
|
+
return record;
|
52
|
+
}
|
53
|
+
|
54
|
+
static char _type [128];
|
55
|
+
|
56
|
+
static const char *
|
57
|
+
rbz_record_type (const char *form, int argc, VALUE *argv)
|
58
|
+
{
|
59
|
+
VALUE charset_from;
|
60
|
+
VALUE charset_to;
|
61
|
+
|
62
|
+
if (argc == 0)
|
63
|
+
return form;
|
64
|
+
|
65
|
+
rb_scan_args (argc, argv, "11", &charset_from, &charset_to);
|
66
|
+
|
67
|
+
memset (_type, 0, sizeof _type);
|
68
|
+
|
69
|
+
if (NIL_P (charset_to))
|
70
|
+
snprintf (_type, sizeof _type, "%s; charset=%s", form,
|
71
|
+
RVAL2CSTR (charset_from));
|
72
|
+
else
|
73
|
+
snprintf (_type, sizeof _type, "%s; charset=%s,%s", form,
|
74
|
+
RVAL2CSTR (charset_from), RVAL2CSTR (charset_to));
|
75
|
+
|
76
|
+
return _type;
|
77
|
+
}
|
78
|
+
|
79
|
+
/*
|
80
|
+
* call-seq:
|
81
|
+
* database(charset_from=nil, charset_to=nil)
|
82
|
+
*
|
83
|
+
* charset_from: the name of the charset to convert from (optional).
|
84
|
+
*
|
85
|
+
* charset_to: the name of the charset to convert to (optional).
|
86
|
+
*
|
87
|
+
* Returns: the database name of the record.
|
88
|
+
*/
|
89
|
+
static VALUE
|
90
|
+
rbz_record_database (int argc, VALUE *argv, VALUE self)
|
91
|
+
{
|
92
|
+
return CSTR2RVAL (ZOOM_record_get (rbz_record_get (self),
|
93
|
+
rbz_record_type ("database", argc, argv),
|
94
|
+
NULL));
|
95
|
+
}
|
96
|
+
|
97
|
+
/*
|
98
|
+
* call-seq:
|
99
|
+
* syntax(charset_from=nil, charset_to=nil)
|
100
|
+
*
|
101
|
+
* charset_from: the name of the charset to convert from (optional).
|
102
|
+
*
|
103
|
+
* charset_to: the name of the charset to convert to (optional).
|
104
|
+
*
|
105
|
+
* Returns: the symbolic transfer syntax name of the record.
|
106
|
+
*/
|
107
|
+
static VALUE
|
108
|
+
rbz_record_syntax (int argc, VALUE *argv, VALUE self)
|
109
|
+
{
|
110
|
+
return CSTR2RVAL (ZOOM_record_get (rbz_record_get (self),
|
111
|
+
rbz_record_type ("syntax", argc, argv),
|
112
|
+
NULL));
|
113
|
+
}
|
114
|
+
|
115
|
+
/*
|
116
|
+
* call-seq:
|
117
|
+
* render(charset_from=nil, charset_to=nil)
|
118
|
+
*
|
119
|
+
* charset_from: the name of the charset to convert from (optional).
|
120
|
+
*
|
121
|
+
* charset_to: the name of the charset to convert to (optional).
|
122
|
+
*
|
123
|
+
* Returns: a display friendly description of the record.
|
124
|
+
*/
|
125
|
+
static VALUE
|
126
|
+
rbz_record_render (int argc, VALUE *argv, VALUE self)
|
127
|
+
{
|
128
|
+
return CSTR2RVAL (ZOOM_record_get (rbz_record_get (self),
|
129
|
+
rbz_record_type ("render", argc, argv),
|
130
|
+
NULL));
|
131
|
+
}
|
132
|
+
|
133
|
+
/*
|
134
|
+
* call-seq:
|
135
|
+
* xml(charset_from=nil, charset_to=nil)
|
136
|
+
*
|
137
|
+
* charset_from: the name of the charset to convert from (optional).
|
138
|
+
*
|
139
|
+
* charset_to: the name of the charset to convert to (optional).
|
140
|
+
*
|
141
|
+
* Returns an XML description of the record. SRW/SRU and Z39.50 records with
|
142
|
+
* transfer syntax XML are returned verbatim. MARC records are returned in
|
143
|
+
* MARCXML (converted from ISO2709 to MARCXML by YAZ). GRS-1 and OPAC records are
|
144
|
+
* not supported for this form.
|
145
|
+
*
|
146
|
+
* Returns: an XML description of the record.
|
147
|
+
*/
|
148
|
+
static VALUE
|
149
|
+
rbz_record_xml (int argc, VALUE *argv, VALUE self)
|
150
|
+
{
|
151
|
+
return CSTR2RVAL (ZOOM_record_get (rbz_record_get (self),
|
152
|
+
rbz_record_type ("xml", argc, argv),
|
153
|
+
NULL));
|
154
|
+
}
|
155
|
+
|
156
|
+
/*
|
157
|
+
* call-seq:
|
158
|
+
* raw
|
159
|
+
*
|
160
|
+
* MARC records are returned in ISO2709.
|
161
|
+
* GRS-1 and OPAC records are not supported for this form.
|
162
|
+
*
|
163
|
+
* Returns: an ISO2709 record.
|
164
|
+
*/
|
165
|
+
|
166
|
+
static VALUE
|
167
|
+
rbz_record_raw (int argc, VALUE *argv, VALUE self)
|
168
|
+
{
|
169
|
+
return CSTR2RVAL (ZOOM_record_get (rbz_record_get (self),
|
170
|
+
rbz_record_type ("raw", argc, argv),
|
171
|
+
NULL));
|
172
|
+
}
|
173
|
+
|
174
|
+
void
|
175
|
+
Init_zoom_record (VALUE mZoom)
|
176
|
+
{
|
177
|
+
VALUE c;
|
178
|
+
|
179
|
+
c = rb_define_class_under (mZoom, "Record", rb_cObject);
|
180
|
+
rb_undef_alloc_func(c);
|
181
|
+
|
182
|
+
rb_undef_method (CLASS_OF (c), "new");
|
183
|
+
|
184
|
+
rb_define_method (c, "database", rbz_record_database, -1);
|
185
|
+
rb_define_method (c, "syntax", rbz_record_syntax, -1);
|
186
|
+
rb_define_method (c, "render", rbz_record_render, -1);
|
187
|
+
rb_define_alias (c, "to_s", "render");
|
188
|
+
rb_define_method (c, "xml", rbz_record_xml, -1);
|
189
|
+
rb_define_method (c, "raw", rbz_record_raw, -1);
|
190
|
+
|
191
|
+
cZoomRecord = c;
|
192
|
+
}
|