ruby_cddb 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/AUTHORS +1 -0
- data/README +33 -0
- data/Rakefile +182 -0
- data/example/example.rb +68 -0
- data/ext/cddb_conn.c +372 -0
- data/ext/cddb_conn.h +15 -0
- data/ext/cddb_disc.c +302 -0
- data/ext/cddb_disc.h +16 -0
- data/ext/cddb_mod.c +78 -0
- data/ext/cddb_mod.h +11 -0
- data/ext/cddb_rb.c +15 -0
- data/ext/cddb_track.c +203 -0
- data/ext/cddb_track.h +18 -0
- data/ext/extconf.rb +6 -0
- data/ext/usage.c +19 -0
- data/ext/usage.h +8 -0
- metadata +61 -0
data/AUTHORS
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Jurgen Van Ham (juvanham@nerdshack.com)
|
data/README
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
= rubycdio
|
2
|
+
== Version
|
3
|
+
version 0.0.1
|
4
|
+
|
5
|
+
== Overview
|
6
|
+
cddb_ruby are the bindings for ruby to use the libcddb, its
|
7
|
+
main use will be in combination with rbcdio
|
8
|
+
|
9
|
+
== Requirements
|
10
|
+
|
11
|
+
I've only tested rcdio on Ruby 1.8.4 - 1.8.6
|
12
|
+
http://libcddb.sourceforge.net with header fiels
|
13
|
+
|
14
|
+
== What's here
|
15
|
+
|
16
|
+
Currently there is a simple example in example/example
|
17
|
+
|
18
|
+
important is to require the 'rbcddb' which will use the .so-file
|
19
|
+
|
20
|
+
Now there are 3 objects and a module available
|
21
|
+
|
22
|
+
CDDB_Connection
|
23
|
+
CDDB_Disc
|
24
|
+
CDDB_Track
|
25
|
+
and the module Rb_CDB
|
26
|
+
|
27
|
+
The CDDB_Disc and CDDB_Track have a to_hash method on top of the
|
28
|
+
methods from cddblib. The constants are defined in the Rb_CDDB
|
29
|
+
which does provide some global settings for the library
|
30
|
+
|
31
|
+
== Todo
|
32
|
+
Documentation in ruby style of these 4 ruby objects, and maybe some
|
33
|
+
more examples
|
data/Rakefile
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
SO_NAME = "rbcddb.so"
|
2
|
+
|
3
|
+
# ------- Default Package ----------
|
4
|
+
VERSION='0.0.1'
|
5
|
+
PKG_NAME = 'ruby_cddb'
|
6
|
+
|
7
|
+
FILES = FileList[
|
8
|
+
'Rakefile',
|
9
|
+
'AUTHORS',
|
10
|
+
'README',
|
11
|
+
'doc/*',
|
12
|
+
'example/*',
|
13
|
+
'ext/**/*.c',
|
14
|
+
'ext/**/*.h',
|
15
|
+
'ext/**/Makefile',
|
16
|
+
'ext/**/extconf.rb',
|
17
|
+
'lib/*.rb',
|
18
|
+
]
|
19
|
+
|
20
|
+
require 'rake/gempackagetask'
|
21
|
+
task :default => [:all]
|
22
|
+
|
23
|
+
# --- Redo Rake::PackageTask::define so tar uses -h to include
|
24
|
+
# files of a symbolic link.
|
25
|
+
module Rake
|
26
|
+
class PackageTask < TaskLib
|
27
|
+
# Create the tasks defined by this task library.
|
28
|
+
def define
|
29
|
+
fail "Version required (or :noversion)" if @version.nil?
|
30
|
+
@version = nil if :noversion == @version
|
31
|
+
|
32
|
+
desc "Build all the packages"
|
33
|
+
task :package
|
34
|
+
|
35
|
+
desc "Force a rebuild of the package files"
|
36
|
+
task :repackage => [:clobber_package, :package]
|
37
|
+
|
38
|
+
desc "Remove package products"
|
39
|
+
task :clobber_package do
|
40
|
+
rm_r package_dir rescue nil
|
41
|
+
end
|
42
|
+
|
43
|
+
task :clobber => [:clobber_package]
|
44
|
+
|
45
|
+
[
|
46
|
+
[need_tar, tgz_file, "z"],
|
47
|
+
[need_tar_gz, tar_gz_file, "z"],
|
48
|
+
[need_tar_bz2, tar_bz2_file, "j"]
|
49
|
+
].each do |(need, file, flag)|
|
50
|
+
if need
|
51
|
+
task :package => ["#{package_dir}/#{file}"]
|
52
|
+
file "#{package_dir}/#{file}" => [package_dir_path] + package_files do
|
53
|
+
chdir(package_dir) do
|
54
|
+
sh %{tar #{flag}hcvf #{file} #{package_name}}
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
if need_zip
|
61
|
+
task :package => ["#{package_dir}/#{zip_file}"]
|
62
|
+
file "#{package_dir}/#{zip_file}" => [package_dir_path] + package_files do
|
63
|
+
chdir(package_dir) do
|
64
|
+
sh %{zip -r #{zip_file} #{package_name}}
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
directory package_dir
|
70
|
+
|
71
|
+
file package_dir_path => @package_files do
|
72
|
+
mkdir_p package_dir rescue nil
|
73
|
+
@package_files.each do |fn|
|
74
|
+
f = File.join(package_dir_path, fn)
|
75
|
+
fdir = File.dirname(f)
|
76
|
+
mkdir_p(fdir) if !File.exist?(fdir)
|
77
|
+
if File.directory?(fn)
|
78
|
+
mkdir_p(f)
|
79
|
+
else
|
80
|
+
rm_f f
|
81
|
+
safe_ln(fn, f)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
self
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
# --------- GEM package ------
|
91
|
+
require 'rubygems'
|
92
|
+
desc "Create GEM spec file"
|
93
|
+
default_spec = Gem::Specification.new do |spec|
|
94
|
+
spec.name = PKG_NAME
|
95
|
+
|
96
|
+
spec.homepage = "http://rubyforge.org/projects/rbcdio/"
|
97
|
+
spec.summary = "Ruby to libcddb ( http://libcddb.sourceforge.net)"
|
98
|
+
spec.description = <<-EOF
|
99
|
+
Libcddb is a C library to access data on a CDDB server (freedb.org).
|
100
|
+
It allows you to:
|
101
|
+
|
102
|
+
1. search the database for possible CD matches;
|
103
|
+
2. retrieve detailed information about a specific CD;
|
104
|
+
3. submit new CD entries to the database.
|
105
|
+
EOF
|
106
|
+
|
107
|
+
spec.version = VERSION
|
108
|
+
|
109
|
+
spec.author = "Jurgen Van Ham"
|
110
|
+
spec.email = "juvanham@nerdshack.com"
|
111
|
+
spec.platform = Gem::Platform::RUBY
|
112
|
+
spec.require_path = "lib"
|
113
|
+
spec.bindir = "bin"
|
114
|
+
spec.executables = []
|
115
|
+
spec.extensions = ["ext/extconf.rb"]
|
116
|
+
spec.autorequire = "rbcddb"
|
117
|
+
spec.files = FILES.to_a
|
118
|
+
# spec.test_files = FileList['tests/**/*']
|
119
|
+
|
120
|
+
spec.required_ruby_version = '>= 1.8.4'
|
121
|
+
spec.date = DateTime.now
|
122
|
+
spec.rubyforge_project = 'ruby-cddb'
|
123
|
+
|
124
|
+
# rdoc
|
125
|
+
spec.has_rdoc = true
|
126
|
+
end
|
127
|
+
|
128
|
+
# Rake task to build the default package
|
129
|
+
desc "Build all the packages (gem, tgz, zip)"
|
130
|
+
Rake::GemPackageTask.new(default_spec) do |pkg|
|
131
|
+
pkg.need_zip = true
|
132
|
+
pkg.need_tar = true
|
133
|
+
end
|
134
|
+
|
135
|
+
|
136
|
+
# --------- Publish ------
|
137
|
+
desc "Publish rubycdio to RubyForge."
|
138
|
+
task :publish do
|
139
|
+
require 'rake/contrib/sshpublisher'
|
140
|
+
|
141
|
+
# Get ruby-debug path
|
142
|
+
ruby_debug_path = File.expand_path(File.dirname(__FILE__))
|
143
|
+
|
144
|
+
publisher = Rake::SshDirPublisher.new("rockyb@rubyforge.org",
|
145
|
+
"/var/www/gforge-projects/rbcdio", ruby_debug_path)
|
146
|
+
end
|
147
|
+
|
148
|
+
desc "Clear temp files"
|
149
|
+
task :clean do
|
150
|
+
sh "make -C ext clean"
|
151
|
+
sh "rm -f ruby_cddb-*.gem"
|
152
|
+
end
|
153
|
+
|
154
|
+
# --------- RDoc Documentation ------
|
155
|
+
require 'rake/rdoctask'
|
156
|
+
Rake::RDocTask.new("rdoc") do |rdoc|
|
157
|
+
rdoc.rdoc_dir = 'doc'
|
158
|
+
rdoc.title = "rbcdio-debug"
|
159
|
+
# Show source inline with line numbers
|
160
|
+
rdoc.options += ("--exclude data --exclude test --exclude lib/cdio/ " +
|
161
|
+
"--exclude lib/iso9660/ --exclude pkg/" ).split()
|
162
|
+
# Make the readme file the start page for the generated html
|
163
|
+
rdoc.options << '--main' << 'README'
|
164
|
+
rdoc.rdoc_files.include('lib/*.rb',
|
165
|
+
'example/*.rb',
|
166
|
+
'example/README',
|
167
|
+
'README')
|
168
|
+
end
|
169
|
+
|
170
|
+
# --------- Regression tests ------
|
171
|
+
require 'rake/testtask'
|
172
|
+
Rake::TestTask.new('test') do |t|
|
173
|
+
t.pattern = 'test/*.rb'
|
174
|
+
t.warning = true
|
175
|
+
end
|
176
|
+
|
177
|
+
# 'check' is an the same thing as 'test'
|
178
|
+
Rake::TestTask.new('check') do |t|
|
179
|
+
t.pattern = 'test/*.rb'
|
180
|
+
t.warning = true
|
181
|
+
end
|
182
|
+
|
data/example/example.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'rubygems'
|
3
|
+
gem 'ruby_cddb'
|
4
|
+
gem 'rbcdio'
|
5
|
+
require 'cdio'
|
6
|
+
require 'rbcddb'
|
7
|
+
|
8
|
+
cddb_conn=CDDB_Connection.new
|
9
|
+
cddb_disk=CDDB_Disc.new
|
10
|
+
cdio_drive = Cdio::Device.new
|
11
|
+
|
12
|
+
if false
|
13
|
+
cddb_conn.http_enable=true
|
14
|
+
cddb_conn.server_name='freedb.freedb.org'
|
15
|
+
cddb_conn.http_proxy_server_name='squid'
|
16
|
+
cddb_conn.http_proxy_server_port=3128
|
17
|
+
cddb_conn.http_proxy_enable=true
|
18
|
+
end
|
19
|
+
|
20
|
+
cdio_drive.open
|
21
|
+
|
22
|
+
trk_cnt=cdio_drive.num_tracks
|
23
|
+
|
24
|
+
(1..trk_cnt).each do |trn|
|
25
|
+
cddb_track=CDDB_Track.new
|
26
|
+
offset=cdio_drive.track(trn).lba
|
27
|
+
cddb_track.frame_offset=offset
|
28
|
+
cddb_disk.add_track(cddb_track)
|
29
|
+
end
|
30
|
+
|
31
|
+
puts "cache dir #{cddb_conn.cache_dir}"
|
32
|
+
# set length without calculating a lot
|
33
|
+
cddb_disk.last_frame_offset=cdio_drive.track(Rubycdio::CDROM_LEADOUT_TRACK).lba
|
34
|
+
|
35
|
+
Rb_CDDB.log_level=Rb_CDDB::LOG_WARN
|
36
|
+
|
37
|
+
|
38
|
+
t=cddb_conn.query_all(cddb_disk)
|
39
|
+
puts "Error : #{cddb_conn.error_str}"
|
40
|
+
|
41
|
+
tr=t.last.track(t.last.track_count-1)
|
42
|
+
tr.title='changed_'+ ((tr.title) || '')
|
43
|
+
|
44
|
+
if t.nil?
|
45
|
+
puts "return nil"
|
46
|
+
else
|
47
|
+
t.each do |d|
|
48
|
+
d.to_hash.each_pair do |k,v|
|
49
|
+
puts "disc #{k} => #{v} "
|
50
|
+
end
|
51
|
+
unless d.nil?
|
52
|
+
tracks=[d.track_first]
|
53
|
+
while ! tracks.last.nil?
|
54
|
+
tracks.push d.track_next
|
55
|
+
end
|
56
|
+
tracks.each do |track|
|
57
|
+
puts ''
|
58
|
+
unless track.nil?
|
59
|
+
track.to_hash.each_pair do |k,v|
|
60
|
+
puts "track #{k}=> #{v} "
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
puts Rb_CDDB::CAT_JAZZ
|
data/ext/cddb_conn.c
ADDED
@@ -0,0 +1,372 @@
|
|
1
|
+
#include<ruby.h>
|
2
|
+
#include<cddb/cddb.h>
|
3
|
+
#include"usage.h"
|
4
|
+
#include"cddb_conn.h"
|
5
|
+
#include"cddb_disc.h"
|
6
|
+
|
7
|
+
/* the ruby class*/
|
8
|
+
VALUE cddb_conn_rb;
|
9
|
+
|
10
|
+
|
11
|
+
static void crb_conn_free(void *p) {
|
12
|
+
cddb_destroy(p);
|
13
|
+
decLibUsage();
|
14
|
+
}
|
15
|
+
|
16
|
+
cddb_conn_t *get_cddb_con_from_Value(VALUE self) {
|
17
|
+
cddb_conn_t *conn = NULL;
|
18
|
+
Data_Get_Struct(self,cddb_conn_t,conn);
|
19
|
+
return conn;
|
20
|
+
}
|
21
|
+
|
22
|
+
VALUE makeValueFrom_cddb_conn_t(cddb_conn_t *conn) {
|
23
|
+
VALUE obj;
|
24
|
+
incLibUsage();
|
25
|
+
obj=Data_Wrap_Struct(cddb_conn_rb,0,crb_conn_free,conn);
|
26
|
+
return obj;
|
27
|
+
}
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
static VALUE crb_conn_alloc(VALUE klass)
|
32
|
+
{
|
33
|
+
VALUE obj;
|
34
|
+
cddb_conn_t *conn = NULL;
|
35
|
+
|
36
|
+
incLibUsage();
|
37
|
+
|
38
|
+
conn = cddb_new();
|
39
|
+
if (conn == NULL) {
|
40
|
+
rb_sys_fail("out of memory, "
|
41
|
+
"unable to create connection structure");
|
42
|
+
}
|
43
|
+
obj=Data_Wrap_Struct(klass,0,crb_conn_free,conn);
|
44
|
+
return obj;
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
static VALUE conn_cddb_set_charset(VALUE self,VALUE cs) {
|
51
|
+
cddb_conn_t *conn;
|
52
|
+
int r=0;
|
53
|
+
conn=get_cddb_con_from_Value(self);
|
54
|
+
r=cddb_set_charset(conn, StringValuePtr(cs));
|
55
|
+
return (r)?Qtrue:Qfalse;
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
static VALUE conn_cddb_set_buf_size(VALUE self,VALUE size) {
|
60
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
61
|
+
cddb_set_buf_size(conn, NUM2INT(size));
|
62
|
+
return self;
|
63
|
+
}
|
64
|
+
|
65
|
+
static VALUE conn_cddb_get_server_name(VALUE self) {
|
66
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
67
|
+
return rb_str_new2(cddb_get_server_name(conn));
|
68
|
+
}
|
69
|
+
|
70
|
+
static VALUE conn_cddb_set_server_name(VALUE self,VALUE server_name) {
|
71
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
72
|
+
cddb_set_server_name(conn,STR2CSTR(server_name));
|
73
|
+
return self;
|
74
|
+
}
|
75
|
+
|
76
|
+
|
77
|
+
|
78
|
+
static VALUE conn_cddb_get_cache_dir(VALUE self) {
|
79
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
80
|
+
return rb_str_new2(cddb_cache_get_dir(conn));
|
81
|
+
}
|
82
|
+
|
83
|
+
static VALUE conn_cddb_set_cache_dir(VALUE self,VALUE cache_dir) {
|
84
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
85
|
+
cddb_cache_set_dir(conn,STR2CSTR(cache_dir));
|
86
|
+
return self;
|
87
|
+
}
|
88
|
+
|
89
|
+
|
90
|
+
|
91
|
+
static VALUE conn_cddb_get_server_port(VALUE self) {
|
92
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
93
|
+
return INT2NUM(cddb_get_server_port(conn));
|
94
|
+
}
|
95
|
+
|
96
|
+
static VALUE conn_cddb_set_server_port(VALUE self,VALUE serverport) {
|
97
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
98
|
+
cddb_set_server_port(conn,NUM2INT(serverport));
|
99
|
+
return self;
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
static VALUE conn_cddb_get_http_proxy_username(VALUE self) {
|
104
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
105
|
+
return rb_str_new2(cddb_get_http_proxy_username(conn));
|
106
|
+
}
|
107
|
+
|
108
|
+
static VALUE conn_cddb_set_http_proxy_username(VALUE self,VALUE username) {
|
109
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
110
|
+
cddb_set_http_proxy_username(conn,STR2CSTR(username));
|
111
|
+
return self;
|
112
|
+
}
|
113
|
+
|
114
|
+
|
115
|
+
static VALUE conn_cddb_get_http_proxy_password(VALUE self) {
|
116
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
117
|
+
return rb_str_new2(cddb_get_http_proxy_password(conn));
|
118
|
+
}
|
119
|
+
|
120
|
+
static VALUE conn_cddb_set_http_proxy_password(VALUE self,VALUE password) {
|
121
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
122
|
+
cddb_set_http_proxy_password(conn,STR2CSTR(password));
|
123
|
+
return self;
|
124
|
+
}
|
125
|
+
|
126
|
+
|
127
|
+
static VALUE conn_cddb_get_timeout(VALUE self) {
|
128
|
+
int r=0;
|
129
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
130
|
+
return INT2NUM(cddb_get_timeout(conn));
|
131
|
+
}
|
132
|
+
|
133
|
+
static VALUE conn_cddb_set_timeout(VALUE self,VALUE ti) {
|
134
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
135
|
+
cddb_set_timeout(conn,(unsigned)NUM2INT(ti));
|
136
|
+
return self;
|
137
|
+
}
|
138
|
+
|
139
|
+
|
140
|
+
static VALUE conn_cddb_get_http_path_query(VALUE self) {
|
141
|
+
cddb_conn_t *conn;
|
142
|
+
int r=0;
|
143
|
+
conn=get_cddb_con_from_Value(self);
|
144
|
+
return rb_str_new2(cddb_get_http_path_query(conn));
|
145
|
+
}
|
146
|
+
|
147
|
+
static VALUE conn_cddb_set_http_path_query(VALUE self,VALUE path) {
|
148
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
149
|
+
cddb_set_http_path_query(conn,STR2CSTR(path));
|
150
|
+
return self;
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
static VALUE conn_cddb_get_http_path_submit(VALUE self) {
|
155
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
156
|
+
return rb_str_new2(cddb_get_http_path_submit(conn));
|
157
|
+
}
|
158
|
+
|
159
|
+
static VALUE conn_cddb_set_http_path_submit(VALUE self,VALUE path) {
|
160
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
161
|
+
cddb_set_http_path_submit(conn,STR2CSTR(path));
|
162
|
+
return self;
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
static VALUE conn_cddb_get_http_enable(VALUE self) {
|
167
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
168
|
+
if (cddb_is_http_enabled(conn))
|
169
|
+
return Qtrue;
|
170
|
+
else
|
171
|
+
return Qfalse;
|
172
|
+
}
|
173
|
+
|
174
|
+
static VALUE conn_cddb_set_http_enable(VALUE self, VALUE state) {
|
175
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
176
|
+
if (state==Qtrue) {
|
177
|
+
cddb_http_enable(conn);
|
178
|
+
}
|
179
|
+
else if (state==Qfalse) {
|
180
|
+
cddb_http_disable(conn);
|
181
|
+
} else {
|
182
|
+
rb_sys_fail("argument is not boolean");
|
183
|
+
}
|
184
|
+
return self;
|
185
|
+
}
|
186
|
+
|
187
|
+
static VALUE conn_cddb_get_http_proxy_enable(VALUE self) {
|
188
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
189
|
+
if (cddb_is_http_proxy_enabled(conn))
|
190
|
+
return Qtrue;
|
191
|
+
else
|
192
|
+
return Qfalse;
|
193
|
+
}
|
194
|
+
|
195
|
+
static VALUE conn_cddb_set_http_proxy_enable(VALUE self, VALUE state) {
|
196
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
197
|
+
|
198
|
+
if (state==Qtrue) {
|
199
|
+
cddb_http_proxy_enable(conn);
|
200
|
+
} else if (state==Qfalse) {
|
201
|
+
cddb_http__proxy_disable(conn);
|
202
|
+
} else {
|
203
|
+
rb_sys_fail("argument is not boolean");
|
204
|
+
}
|
205
|
+
return self;
|
206
|
+
}
|
207
|
+
|
208
|
+
|
209
|
+
static VALUE conn_cddb_set_cache_enable(VALUE self, VALUE state) {
|
210
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
211
|
+
|
212
|
+
if (state==Qtrue) {
|
213
|
+
cddb_cache_enable(conn);
|
214
|
+
} else if (state==Qfalse) {
|
215
|
+
cddb_cache_disable(conn);
|
216
|
+
} else {
|
217
|
+
rb_sys_fail("argument is not boolean");
|
218
|
+
}
|
219
|
+
return self;
|
220
|
+
}
|
221
|
+
|
222
|
+
static VALUE conn_cddb_get_http_proxy_server_name(VALUE self) {
|
223
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
224
|
+
return rb_str_new2(cddb_get_http_proxy_server_name(conn));
|
225
|
+
}
|
226
|
+
|
227
|
+
static VALUE conn_cddb_set_http_proxy_server_name(VALUE self,VALUE name) {
|
228
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
229
|
+
cddb_set_http_proxy_server_name(conn,STR2CSTR(name));
|
230
|
+
return self;
|
231
|
+
}
|
232
|
+
|
233
|
+
static VALUE conn_cddb_get_http_proxy_server_port(VALUE self) {
|
234
|
+
cddb_conn_t *conn;
|
235
|
+
int r=0;
|
236
|
+
Data_Get_Struct(self,cddb_conn_t,conn);
|
237
|
+
return INT2NUM(cddb_get_http_proxy_server_port(conn));
|
238
|
+
}
|
239
|
+
|
240
|
+
static VALUE conn_cddb_set_http_proxy_server_port(VALUE self,VALUE serverport) {
|
241
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
242
|
+
cddb_set_http_proxy_server_port(conn,NUM2INT(serverport));
|
243
|
+
return self;
|
244
|
+
}
|
245
|
+
|
246
|
+
|
247
|
+
/** command **/
|
248
|
+
|
249
|
+
static VALUE conn_cddb_read(VALUE self,VALUE rdisc) {
|
250
|
+
int count=0;
|
251
|
+
VALUE arr=0;
|
252
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
253
|
+
cddb_disc_t *disc=get_cddb_disc_from_Value(rdisc);
|
254
|
+
count=cddb_read(conn,disc);
|
255
|
+
if (count==-1)
|
256
|
+
return Qnil;
|
257
|
+
return rdisc;
|
258
|
+
}
|
259
|
+
|
260
|
+
static VALUE conn_cddb_query_all(VALUE self,VALUE rdisc) {
|
261
|
+
int count=0;
|
262
|
+
VALUE arr=0;
|
263
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
264
|
+
cddb_disc_t *disc=get_cddb_disc_from_Value(rdisc);
|
265
|
+
disc=cddb_disc_clone(disc);
|
266
|
+
count=cddb_query(conn,disc);
|
267
|
+
if (count==-1)
|
268
|
+
return Qnil;
|
269
|
+
|
270
|
+
arr=rb_ary_new2(count);
|
271
|
+
if (disc) {
|
272
|
+
rb_ary_push(arr,makeValueFrom_cddb_disc_t(cddb_disc_clone(disc)));
|
273
|
+
}
|
274
|
+
while (--count>0) {
|
275
|
+
cddb_query_next(conn,disc);
|
276
|
+
if (disc) {
|
277
|
+
rb_ary_push(arr,makeValueFrom_cddb_disc_t(cddb_disc_clone(disc)));
|
278
|
+
}
|
279
|
+
}
|
280
|
+
cddb_disc_destroy(disc);
|
281
|
+
return arr;
|
282
|
+
}
|
283
|
+
|
284
|
+
static VALUE conn_cddb_set_search_fields(VALUE self,VALUE fields) {
|
285
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
286
|
+
cddb_search_set_fields(conn, NUM2UINT(fields));
|
287
|
+
return self;
|
288
|
+
}
|
289
|
+
|
290
|
+
static VALUE conn_cddb_set_search_categories(VALUE self,VALUE categories) {
|
291
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
292
|
+
cddb_search_set_categories(conn, NUM2UINT(categories));
|
293
|
+
return self;
|
294
|
+
}
|
295
|
+
|
296
|
+
static VALUE conn_cddb_search_all(VALUE self,VALUE str) {
|
297
|
+
int count;
|
298
|
+
VALUE arr;
|
299
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
300
|
+
cddb_disc_t *disc=cddb_disc_new();
|
301
|
+
disc=cddb_disc_clone(disc);
|
302
|
+
count=cddb_search(conn,disc,STR2CSTR(str));
|
303
|
+
if (count==-1)
|
304
|
+
return Qnil;
|
305
|
+
|
306
|
+
arr=rb_ary_new2(count);
|
307
|
+
rb_ary_push(arr,makeValueFrom_cddb_disc_t(cddb_disc_clone(disc)));
|
308
|
+
|
309
|
+
while (--count>0) {
|
310
|
+
cddb_search_next(conn,disc);
|
311
|
+
rb_ary_push(arr,makeValueFrom_cddb_disc_t(cddb_disc_clone(disc)));
|
312
|
+
}
|
313
|
+
cddb_disc_destroy(disc);
|
314
|
+
return arr;
|
315
|
+
}
|
316
|
+
|
317
|
+
static VALUE conn_cddb_get_error(VALUE self) {
|
318
|
+
cddb_conn_t *conn=get_cddb_con_from_Value(self);
|
319
|
+
cddb_error_t errnum=cddb_errno(conn);
|
320
|
+
if (errnum==CDDB_ERR_OK ) {
|
321
|
+
return Qnil;
|
322
|
+
} else {
|
323
|
+
return rb_str_new2(cddb_error_str(errnum));
|
324
|
+
}
|
325
|
+
}
|
326
|
+
|
327
|
+
/** **/
|
328
|
+
#define METHOD(name,method,parCount) \
|
329
|
+
rb_define_method(cddb_conn_rb, \
|
330
|
+
name,method,parCount)
|
331
|
+
|
332
|
+
|
333
|
+
void init_cddb_conn() {
|
334
|
+
cddb_conn_rb=rb_define_class("CDDB_Connection",rb_cObject);
|
335
|
+
rb_define_alloc_func(cddb_conn_rb,crb_conn_alloc);
|
336
|
+
METHOD("charset=" ,conn_cddb_set_charset,1);
|
337
|
+
METHOD("buf_size=" ,conn_cddb_set_buf_size,1);
|
338
|
+
METHOD("server_name" ,conn_cddb_get_server_name,0);
|
339
|
+
METHOD("server_name=",conn_cddb_set_server_name,1);
|
340
|
+
METHOD("cache_dir" ,conn_cddb_get_cache_dir,0);
|
341
|
+
METHOD("cache_dir=",conn_cddb_set_cache_dir,1);
|
342
|
+
METHOD("server_port" ,conn_cddb_get_server_port,0);
|
343
|
+
METHOD("server_port=",conn_cddb_set_server_port,1);
|
344
|
+
METHOD("timeout" ,conn_cddb_get_timeout,0);
|
345
|
+
METHOD("timeout=" ,conn_cddb_set_timeout,1);
|
346
|
+
METHOD("http_path_query" ,conn_cddb_get_http_path_query,0);
|
347
|
+
METHOD("http_path_query=" ,conn_cddb_set_http_path_query,1);
|
348
|
+
METHOD("http_path_submit" ,conn_cddb_get_http_path_submit,0);
|
349
|
+
METHOD("http_path_submit=" ,conn_cddb_set_http_path_submit,1);
|
350
|
+
METHOD("http_enabled?",conn_cddb_get_http_enable,0);
|
351
|
+
METHOD("http_enable=" ,conn_cddb_set_http_enable,1);
|
352
|
+
METHOD("cache_enable=",conn_cddb_set_cache_enable,1);
|
353
|
+
|
354
|
+
METHOD("http_proxy_enabled?",conn_cddb_get_http_proxy_enable,0);
|
355
|
+
METHOD("http_proxy_enable=" ,conn_cddb_set_http_proxy_enable,1);
|
356
|
+
METHOD("http_proxy_server_name" ,conn_cddb_get_http_proxy_server_name,0);
|
357
|
+
METHOD("http_proxy_server_name=",conn_cddb_set_http_proxy_server_name,1);
|
358
|
+
METHOD("http_proxy_server_port" ,conn_cddb_get_http_proxy_server_port,0);
|
359
|
+
METHOD("http_proxy_server_port=",conn_cddb_set_http_proxy_server_port,1);
|
360
|
+
METHOD("http_proxy_username" ,conn_cddb_get_http_proxy_username,0);
|
361
|
+
METHOD("http_proxy_username=",conn_cddb_set_http_proxy_username,1);
|
362
|
+
METHOD("http_proxy_password" ,conn_cddb_get_http_proxy_password,0);
|
363
|
+
METHOD("http_proxy_password=",conn_cddb_set_http_proxy_password,1);
|
364
|
+
|
365
|
+
METHOD("read",conn_cddb_read,1);
|
366
|
+
METHOD("error_str",conn_cddb_get_error,0);
|
367
|
+
|
368
|
+
METHOD("query_all",conn_cddb_query_all,1);
|
369
|
+
METHOD("search_fields=",conn_cddb_set_search_fields,1);
|
370
|
+
METHOD("search_categories=",conn_cddb_set_search_categories,1);
|
371
|
+
METHOD("search_all",conn_cddb_search_all,1);
|
372
|
+
}
|