idn-mihu 0.0.2

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/Rakefile ADDED
@@ -0,0 +1,126 @@
1
+ # Rakefile for LibIDN Ruby Bindings.
2
+ #
3
+ # Copyright (c) 2005 Erik Abele. All rights reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # Please see the file called LICENSE for further details.
8
+ #
9
+ # You may also obtain a copy of the License at
10
+ #
11
+ # * http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ # This software is OSI Certified Open Source Software.
20
+ # OSI Certified is a certification mark of the Open Source Initiative.
21
+
22
+ require 'rake'
23
+ require 'rake/testtask'
24
+ require 'rake/rdoctask'
25
+ require 'rake/contrib/sshpublisher'
26
+
27
+ TEST_FILES = FileList[
28
+ 'test/ts_*.rb'
29
+ ]
30
+
31
+ DOC_FILES = FileList[
32
+ 'README', 'CHANGES', 'LICENSE', 'lib/**/*.rb',
33
+ 'ext/idna.c', 'ext/punycode.c', 'ext/stringprep.c', 'ext/idn.c'
34
+ ]
35
+
36
+ INFO_NOTE = <<EOL
37
+ Please note that if the required libraries or header files can only be
38
+ found in a non-standard location an alternative search path has to be
39
+ specified when executing Rake:
40
+ rake ext IDN_DIR=/path/to/non/standard/location
41
+ EOL
42
+
43
+ task :default do
44
+ puts "Please see 'rake --tasks' for an overview of the available tasks."
45
+ end
46
+
47
+ desc 'Build all the extensions'
48
+ task :ext do
49
+ extconf_args = ''
50
+
51
+ unless ENV['IDN_DIR'].nil?
52
+ extconf_args = "--with-idn-dir=#{ENV['IDN_DIR']}"
53
+ end
54
+
55
+ cd 'ext' do
56
+ unless system("ruby extconf.rb #{extconf_args}")
57
+ STDERR.puts "ERROR: could not configure extension!\n" +
58
+ "\n#{INFO_NOTE}\n"
59
+ break
60
+ end
61
+
62
+ unless system('make')
63
+ STDERR.puts 'ERROR: could not build extension!'
64
+ break
65
+ end
66
+ end
67
+ end
68
+
69
+ desc 'Install (and build) extensions'
70
+ task :install => [:ext] do
71
+ cd 'ext' do
72
+ unless system('make install')
73
+ STDERR.puts 'ERROR: could not install extension!'
74
+ break
75
+ end
76
+ end
77
+ end
78
+
79
+ desc 'Remove extension products'
80
+ task :clobber_ext do
81
+ FileList['ext/**/*'].each do |file|
82
+ unless FileList['ext/**/*.{c,h,rb}'].include?(file)
83
+ rm_r file if File.exists?(file)
84
+ end
85
+ end
86
+ end
87
+
88
+ desc 'Force a rebuild of the extension files'
89
+ task :reext => [:clobber_ext, :ext]
90
+
91
+ desc 'Remove all files created during the build process'
92
+ task :clobber => [:clobber_doc, :clobber_ext, :clobber_package]
93
+
94
+ Rake::TestTask.new do |test|
95
+ test.test_files = TEST_FILES
96
+ test.verbose = true
97
+ test.warning = true
98
+ end
99
+
100
+ Rake::RDocTask.new('doc') do |rdoc|
101
+ rdoc.rdoc_files = DOC_FILES
102
+ rdoc.rdoc_dir = 'doc'
103
+ rdoc.main = 'README'
104
+ rdoc.title = 'LibIDN Ruby Bindings Documentation'
105
+ rdoc.options << '-N' << '-S' << '-w 2'
106
+ end
107
+
108
+ desc 'Publish the documentation'
109
+ task :publish_doc => [:redoc] do
110
+ Rake::SshDirPublisher.new(PKG_EMAIL,
111
+ "/var/www/gforge-projects/idn/docs", 'doc').upload
112
+ end
113
+
114
+ begin
115
+ require 'rubygems'
116
+ require 'rake/gempackagetask'
117
+ spec = eval(File.read('idn.gemspec'))
118
+
119
+ Rake::GemPackageTask.new(spec) do |pkg|
120
+ pkg.need_zip = true
121
+ pkg.need_tar_gz = true
122
+ end
123
+ rescue Exception
124
+ nil
125
+ end
126
+
data/ext/extconf.rb ADDED
@@ -0,0 +1,56 @@
1
+ # Makefile configuration for LibIDN Ruby Bindings.
2
+ #
3
+ # Copyright (c) 2005 Erik Abele. All rights reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # Please see the file called LICENSE for further details.
8
+ #
9
+ # You may also obtain a copy of the License at
10
+ #
11
+ # * http://www.apache.org/licenses/LICENSE-2.0
12
+ #
13
+ # Unless required by applicable law or agreed to in writing, software
14
+ # distributed under the License is distributed on an "AS IS" BASIS,
15
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ # See the License for the specific language governing permissions and
17
+ # limitations under the License.
18
+ #
19
+ # This software is OSI Certified Open Source Software.
20
+ # OSI Certified is a certification mark of the Open Source Initiative.
21
+
22
+ require 'mkmf'
23
+
24
+ @libs = ['idn']
25
+ @headers = ['idna.h', 'punycode.h', 'stringprep.h']
26
+
27
+ INFO_NOTE = <<EOL
28
+ Please install the GNU IDN library or alternatively specify at least one
29
+ of the following options if the library can only be found in a non-standard
30
+ location:
31
+ --with-idn-dir=/path/to/non/standard/location
32
+ or
33
+ --with-idn-lib=/path/to/non/standard/location/lib
34
+ --with-idn-include=/path/to/non/standard/location/include
35
+ EOL
36
+
37
+ dir_config('idn')
38
+
39
+ @libs.each do |lib|
40
+ unless have_library(lib)
41
+ STDERR.puts "ERROR: could not find #{lib} library!\n" +
42
+ "\n#{INFO_NOTE}\n"
43
+ exit 1
44
+ end
45
+ end
46
+
47
+ @headers.each do |header|
48
+ unless have_header(header)
49
+ STDERR.puts "ERROR: could not find #{header} header file!\n" +
50
+ "\n#{INFO_NOTE}\n"
51
+ exit 1
52
+ end
53
+ end
54
+
55
+ $CFLAGS += ' -Wall' unless $CFLAGS.split.include? '-Wall'
56
+ create_makefile('idn')
data/ext/idn.c ADDED
@@ -0,0 +1,59 @@
1
+ /*
2
+ * Copyright (c) 2005 Erik Abele. All rights reserved.
3
+ * Portions Copyright (c) 2005 Yuki Mitsui. All rights reserved.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * Please see the file called LICENSE for further details.
8
+ *
9
+ * You may also obtain a copy of the License at
10
+ *
11
+ * * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ * This software is OSI Certified Open Source Software.
20
+ * OSI Certified is a certification mark of the Open Source Initiative.
21
+ */
22
+
23
+ #include <ruby.h>
24
+ #include "idn.h"
25
+
26
+ /*
27
+ * Document-class: IDN
28
+ * The main module of LibIDN Ruby Bindings.
29
+ *
30
+ * === Example usage
31
+ *
32
+ * require 'idn'
33
+ * include IDN
34
+ *
35
+ * ...
36
+ */
37
+
38
+ VALUE mIDN;
39
+
40
+ /*
41
+ * Document-class: IDN::IDNError
42
+ * The superclass for all exceptions raised by the IDN extension.
43
+ */
44
+
45
+ VALUE eIDNError;
46
+
47
+ /*
48
+ * Module Initialization.
49
+ */
50
+
51
+ void Init_idn(void)
52
+ {
53
+ mIDN = rb_define_module("IDN");
54
+ eIDNError = rb_define_class_under(mIDN, "IDNError", rb_eStandardError);
55
+
56
+ init_idna();
57
+ init_punycode();
58
+ init_stringprep();
59
+ }
data/ext/idn.h ADDED
@@ -0,0 +1,58 @@
1
+ /*
2
+ * Copyright (c) 2005 Erik Abele. All rights reserved.
3
+ * Portions Copyright (c) 2005 Yuki Mitsui. All rights reserved.
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * Please see the file called LICENSE for further details.
8
+ *
9
+ * You may also obtain a copy of the License at
10
+ *
11
+ * * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ *
19
+ * This software is OSI Certified Open Source Software.
20
+ * OSI Certified is a certification mark of the Open Source Initiative.
21
+ */
22
+
23
+ #ifndef ___IDN_IDN_H_
24
+ #define ___IDN_IDN_H_
25
+
26
+ #include <ruby.h>
27
+
28
+ /*
29
+ * idn.c
30
+ */
31
+ extern VALUE mIDN;
32
+ extern VALUE eIDNError;
33
+
34
+ /*
35
+ * idna.c
36
+ */
37
+ extern VALUE mIdna;
38
+ extern VALUE eIdnaError;
39
+
40
+ void init_idna(void);
41
+
42
+ /*
43
+ * punycode.c
44
+ */
45
+ extern VALUE mPunycode;
46
+ extern VALUE ePunycodeError;
47
+
48
+ void init_punycode(void);
49
+
50
+ /*
51
+ * stringprep.c
52
+ */
53
+ extern VALUE mStringprep;
54
+ extern VALUE eStringprepError;
55
+
56
+ void init_stringprep(void);
57
+
58
+ #endif /* ___IDN_IDN_H_ */
data/ext/idna.c ADDED
@@ -0,0 +1,164 @@
1
+ /*
2
+ * Copyright (c) 2005 Erik Abele. All rights reserved.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * Please see the file called LICENSE for further details.
7
+ *
8
+ * You may also obtain a copy of the License at
9
+ *
10
+ * * http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software
13
+ * distributed under the License is distributed on an "AS IS" BASIS,
14
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ * See the License for the specific language governing permissions and
16
+ * limitations under the License.
17
+ *
18
+ * This software is OSI Certified Open Source Software.
19
+ * OSI Certified is a certification mark of the Open Source Initiative.
20
+ */
21
+
22
+ #include <stdlib.h>
23
+ #include <ruby.h>
24
+ #include <idna.h>
25
+ #include "idn.h"
26
+
27
+ /*
28
+ * Document-class: IDN::Idna
29
+ * The Idna module of LibIDN Ruby Bindings.
30
+ *
31
+ * === Example usage
32
+ *
33
+ * require 'idn'
34
+ * include IDN
35
+ *
36
+ * puts 'ACE-Prefix: ' + Idna::ACE_PREFIX
37
+ *
38
+ * domain = Idna.toUnicode('xn--rksmrgs-5wao1o.josefsson.org',
39
+ * Idna::USE_STD3_ASCII_RULES | Idna::ALLOW_UNASSIGNED)
40
+ *
41
+ * === Constants
42
+ *
43
+ * <b>ACE_PREFIX</b>
44
+ * - The ACE prefix: 'xn--'.
45
+ *
46
+ * <b>ALLOW_UNASSIGNED</b>
47
+ * - Used as flag for toASCII/toUnicode.
48
+ *
49
+ * <b>USE_STD3_ASCII_RULES</b>
50
+ * - Used as flag for toASCII/toUnicode.
51
+ */
52
+
53
+ VALUE mIdna;
54
+
55
+ /*
56
+ * Document-class: IDN::Idna::IdnaError
57
+ * The base class for all exceptions raised by the IDN::Idna module.
58
+ */
59
+
60
+ VALUE eIdnaError;
61
+
62
+ /*
63
+ * call-seq:
64
+ * IDN::Idna.toASCII(string, flags=nil) => string
65
+ *
66
+ * Converts a domain name in UTF-8 format into an ASCII string. The domain
67
+ * name may contain several labels, separated by dots.
68
+ *
69
+ * Raises IDN::Idna::IdnaError on failure.
70
+ */
71
+
72
+ static VALUE toASCII(int argc, VALUE argv[], VALUE self)
73
+ {
74
+ int rc;
75
+ char *buf;
76
+ VALUE str, flags, retv;
77
+
78
+ rb_scan_args(argc, argv, "11", &str, &flags);
79
+ str = rb_check_convert_type(str, T_STRING, "String", "to_s");
80
+
81
+ if (flags != Qnil) {
82
+ Check_Type(flags, T_FIXNUM);
83
+ flags = FIX2INT(flags);
84
+ } else {
85
+ flags = 0x0000;
86
+ }
87
+
88
+ rc = idna_to_ascii_8z(RSTRING_PTR(str), &buf, flags);
89
+
90
+ if (rc != IDNA_SUCCESS) {
91
+ xfree(buf);
92
+ rb_raise(eIdnaError, "%s (%d)", idna_strerror(rc), rc);
93
+ return Qnil;
94
+ }
95
+
96
+ retv = rb_str_new2(buf);
97
+ xfree(buf);
98
+ return retv;
99
+ }
100
+
101
+ /*
102
+ * call-seq:
103
+ * IDN::Idna.toUnicode(string, flags=nil) => string
104
+ *
105
+ * Converts a possibly ACE encoded domain name in UTF-8 format into an
106
+ * UTF-8 string. The domain name may contain several labels, separated
107
+ * by dots.
108
+ *
109
+ * Raises IDN::Idna::IdnaError on failure.
110
+ */
111
+
112
+ static VALUE toUnicode(int argc, VALUE argv[], VALUE self)
113
+ {
114
+ int rc;
115
+ char *buf;
116
+ VALUE str, flags, retv;
117
+
118
+ rb_scan_args(argc, argv, "11", &str, &flags);
119
+ str = rb_check_convert_type(str, T_STRING, "String", "to_s");
120
+
121
+ if (flags != Qnil) {
122
+ Check_Type(flags, T_FIXNUM);
123
+ flags = FIX2INT(flags);
124
+ } else {
125
+ flags = 0x0000;
126
+ }
127
+
128
+ rc = idna_to_unicode_8z8z(RSTRING_PTR(str), &buf, flags);
129
+
130
+ if (rc != IDNA_SUCCESS) {
131
+ xfree(buf);
132
+ rb_raise(eIdnaError, "%s (%d)", idna_strerror(rc), rc);
133
+ return Qnil;
134
+ }
135
+
136
+ retv = rb_str_new2(buf);
137
+ xfree(buf);
138
+ return retv;
139
+ }
140
+
141
+ /*
142
+ * Module Initialization.
143
+ */
144
+
145
+ void init_idna(void)
146
+ {
147
+ #ifdef mIDN_RDOC_HACK
148
+ mIDN = rb_define_module("IDN");
149
+ eIDNError = rb_define_class_under(mIDN, "IDNError", rb_eStandardError);
150
+ #endif
151
+
152
+ mIdna = rb_define_module_under(mIDN, "Idna");
153
+ eIdnaError = rb_define_class_under(mIdna, "IdnaError", eIDNError);
154
+
155
+ rb_define_const(mIdna, "ACE_PREFIX",
156
+ rb_str_new2(IDNA_ACE_PREFIX));
157
+ rb_define_const(mIdna, "ALLOW_UNASSIGNED",
158
+ INT2FIX(IDNA_ALLOW_UNASSIGNED));
159
+ rb_define_const(mIdna, "USE_STD3_ASCII_RULES",
160
+ INT2FIX(IDNA_USE_STD3_ASCII_RULES));
161
+
162
+ rb_define_singleton_method(mIdna, "toASCII", toASCII, -1);
163
+ rb_define_singleton_method(mIdna, "toUnicode", toUnicode, -1);
164
+ }