rubyfb 0.5.2-x86-mswin32-60
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/LICENSE +411 -0
- data/Manifest +75 -0
- data/README +460 -0
- data/Rakefile +21 -0
- data/examples/example01.rb +65 -0
- data/ext/AddUser.c +464 -0
- data/ext/AddUser.h +37 -0
- data/ext/Backup.c +783 -0
- data/ext/Backup.h +37 -0
- data/ext/Blob.c +421 -0
- data/ext/Blob.h +65 -0
- data/ext/Common.c +54 -0
- data/ext/Common.h +37 -0
- data/ext/Connection.c +863 -0
- data/ext/Connection.h +50 -0
- data/ext/DataArea.c +274 -0
- data/ext/DataArea.h +38 -0
- data/ext/Database.c +449 -0
- data/ext/Database.h +48 -0
- data/ext/FireRuby.c +240 -0
- data/ext/FireRuby.h +50 -0
- data/ext/FireRubyException.c +268 -0
- data/ext/FireRubyException.h +51 -0
- data/ext/Generator.c +689 -0
- data/ext/Generator.h +53 -0
- data/ext/RemoveUser.c +212 -0
- data/ext/RemoveUser.h +37 -0
- data/ext/Restore.c +855 -0
- data/ext/Restore.h +37 -0
- data/ext/ResultSet.c +810 -0
- data/ext/ResultSet.h +60 -0
- data/ext/Row.c +965 -0
- data/ext/Row.h +55 -0
- data/ext/ServiceManager.c +316 -0
- data/ext/ServiceManager.h +48 -0
- data/ext/Services.c +124 -0
- data/ext/Services.h +42 -0
- data/ext/Statement.c +785 -0
- data/ext/Statement.h +62 -0
- data/ext/Transaction.c +684 -0
- data/ext/Transaction.h +50 -0
- data/ext/TypeMap.c +1182 -0
- data/ext/TypeMap.h +51 -0
- data/ext/extconf.rb +30 -0
- data/lib/SQLType.rb +224 -0
- data/lib/active_record/connection_adapters/rubyfb_adapter.rb +805 -0
- data/lib/mkdoc +1 -0
- data/lib/rubyfb.rb +2 -0
- data/lib/rubyfb_lib.so +0 -0
- data/lib/src.rb +1800 -0
- data/mswin32fb/fbclient_ms.lib +0 -0
- data/mswin32fb/ibase.h +2555 -0
- data/mswin32fb/iberror.h +1741 -0
- data/rubyfb.gemspec +31 -0
- data/test/AddRemoveUserTest.rb +56 -0
- data/test/BackupRestoreTest.rb +99 -0
- data/test/BlobTest.rb +57 -0
- data/test/CharacterSetTest.rb +63 -0
- data/test/ConnectionTest.rb +111 -0
- data/test/DDLTest.rb +54 -0
- data/test/DatabaseTest.rb +83 -0
- data/test/GeneratorTest.rb +50 -0
- data/test/KeyTest.rb +140 -0
- data/test/ResultSetTest.rb +162 -0
- data/test/RoleTest.rb +73 -0
- data/test/RowCountTest.rb +65 -0
- data/test/RowTest.rb +203 -0
- data/test/SQLTest.rb +182 -0
- data/test/SQLTypeTest.rb +101 -0
- data/test/ServiceManagerTest.rb +29 -0
- data/test/StatementTest.rb +135 -0
- data/test/TestSetup.rb +11 -0
- data/test/TransactionTest.rb +112 -0
- data/test/TypeTest.rb +92 -0
- data/test/UnitTest.rb +65 -0
- metadata +143 -0
data/Rakefile
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'echoe'
|
2
|
+
e = Echoe.new('rubyfb', '0.5.2') do |p|
|
3
|
+
p.description = "Firebird SQL access library"
|
4
|
+
p.url = "http://rubyforge.org/projects/rubyfb"
|
5
|
+
p.author = "George Georgiev"
|
6
|
+
p.email = "georgiev@heatbs.com"
|
7
|
+
p.rdoc_pattern = ["{examples,ext,lib}/*.rb", "CHANGELOG", "README", "LICENSE"]
|
8
|
+
p.need_tar_gz = !PLATFORM.include?("win32")
|
9
|
+
|
10
|
+
if ARGV.include? "binpkg"
|
11
|
+
p.platform=Gem::Platform::CURRENT
|
12
|
+
p.eval = Proc.new {
|
13
|
+
self.extensions=nil
|
14
|
+
self.platform=Gem::Platform::CURRENT
|
15
|
+
}
|
16
|
+
end
|
17
|
+
end
|
18
|
+
e.clean_pattern = e.clean_pattern - e.clean_pattern.grep(/^lib/)
|
19
|
+
e.clean_pattern = e.clean_pattern - e.clean_pattern.grep(/^mswin32fb/)
|
20
|
+
|
21
|
+
task :binpkg => [:compile, :repackage]
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require_gem 'fireruby'
|
5
|
+
|
6
|
+
include FireRuby
|
7
|
+
|
8
|
+
# Database details constants.
|
9
|
+
DB_FILE = "localhost:#{File.expand_path('.')}#{File::SEPARATOR}example.fdb"
|
10
|
+
DB_USER_NAME = "sysdba"
|
11
|
+
DB_PASSWORD = "masterkey"
|
12
|
+
|
13
|
+
# SQL constants.
|
14
|
+
CREATE_TABLE_SQL = 'CREATE TABLE TESTTABLE (TESTID INTEGER NOT NULL PRIMARY '\
|
15
|
+
'KEY, TESTTEXT VARCHAR(100), TESTFLOAT NUMERIC(6,2), '\
|
16
|
+
'CREATED TIMESTAMP)'
|
17
|
+
DROP_TABLE_SQL = 'DROP TABLE TESTTABLE'
|
18
|
+
INSERT_SQL = 'INSERT INTO TESTTABLE VALUES(?, ?, ?, ?)'
|
19
|
+
SELECT_SQL = 'SELECT * FROM TESTTABLE'
|
20
|
+
|
21
|
+
begin
|
22
|
+
# Check if the database file exists.
|
23
|
+
db = nil
|
24
|
+
if File.exist?(DB_FILE) == false
|
25
|
+
# Create the database file.
|
26
|
+
db = Database.create(DB_FILE, DB_USER_NAME, DB_PASSWORD, 1024, 'ASCII')
|
27
|
+
else
|
28
|
+
# Create the databse object.
|
29
|
+
db = Database.new(DB_FILE)
|
30
|
+
end
|
31
|
+
|
32
|
+
# Obtain a connection to the database.
|
33
|
+
db.connect(DB_USER_NAME, DB_PASSWORD) do |cxn|
|
34
|
+
# Create the database table.
|
35
|
+
cxn.execute_immediate(CREATE_TABLE_SQL)
|
36
|
+
|
37
|
+
# Insert 50 rows into the database.
|
38
|
+
decimal = 1.0
|
39
|
+
cxn.start_transaction do |tx|
|
40
|
+
s = Statement.new(cxn, tx, INSERT_SQL, 3)
|
41
|
+
1.upto(20) do |number|
|
42
|
+
s.execute_for([number, "Number is #{number}.", decimal, Time.new])
|
43
|
+
decimal = decimal + 0.24
|
44
|
+
end
|
45
|
+
s.close
|
46
|
+
end
|
47
|
+
|
48
|
+
# Select back the rows inserted and display them
|
49
|
+
rows = cxn.execute_immediate(SELECT_SQL)
|
50
|
+
rows.each do |row|
|
51
|
+
puts "-----"
|
52
|
+
puts "Test Id: #{row['TESTID']}"
|
53
|
+
puts "Test Text: '#{row['TESTTEXT']}'"
|
54
|
+
puts "Test Float: #{row['TESTFLOAT']}"
|
55
|
+
puts "Test Created: #{row['CREATED']}"
|
56
|
+
puts "-----"
|
57
|
+
end
|
58
|
+
rows.close
|
59
|
+
|
60
|
+
# Drop the table.
|
61
|
+
cxn.execute_immediate(DROP_TABLE_SQL)
|
62
|
+
end
|
63
|
+
rescue Excepton => error
|
64
|
+
puts error.message
|
65
|
+
end
|
data/ext/AddUser.c
ADDED
@@ -0,0 +1,464 @@
|
|
1
|
+
/*------------------------------------------------------------------------------
|
2
|
+
* AddUser.c
|
3
|
+
*----------------------------------------------------------------------------*/
|
4
|
+
/**
|
5
|
+
* Copyright � Peter Wood, 2005
|
6
|
+
*
|
7
|
+
* The contents of this file are subject to the Mozilla Public License Version
|
8
|
+
* 1.1 (the "License"); you may not use this file except in compliance with the
|
9
|
+
* License. You may obtain a copy of the License at
|
10
|
+
*
|
11
|
+
* http://www.mozilla.org/MPL/
|
12
|
+
*
|
13
|
+
* Software distributed under the License is distributed on an "AS IS" basis,
|
14
|
+
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
|
15
|
+
* the specificlanguage governing rights and limitations under the License.
|
16
|
+
*
|
17
|
+
* The Original Code is the FireRuby extension for the Ruby language.
|
18
|
+
*
|
19
|
+
* The Initial Developer of the Original Code is Peter Wood. All Rights
|
20
|
+
* Reserved.
|
21
|
+
*
|
22
|
+
* @author Peter Wood
|
23
|
+
* @version 1.0
|
24
|
+
*/
|
25
|
+
|
26
|
+
/* Includes. */
|
27
|
+
#include "AddUser.h"
|
28
|
+
#include "ibase.h"
|
29
|
+
#include "ServiceManager.h"
|
30
|
+
|
31
|
+
/* Function prototypes. */
|
32
|
+
static VALUE initializeAddUser(int, VALUE *, VALUE);
|
33
|
+
static VALUE getUserName(VALUE);
|
34
|
+
static VALUE setUserName(VALUE, VALUE);
|
35
|
+
static VALUE getUserPassword(VALUE);
|
36
|
+
static VALUE setUserPassword(VALUE, VALUE);
|
37
|
+
static VALUE getUserFirstName(VALUE);
|
38
|
+
static VALUE setUserFirstName(VALUE, VALUE);
|
39
|
+
static VALUE getUserMiddleName(VALUE);
|
40
|
+
static VALUE setUserMiddleName(VALUE, VALUE);
|
41
|
+
static VALUE getUserLastName(VALUE);
|
42
|
+
static VALUE setUserLastName(VALUE, VALUE);
|
43
|
+
static void createAddUserBuffer(VALUE, char **, short *);
|
44
|
+
|
45
|
+
|
46
|
+
/* Globals. */
|
47
|
+
VALUE cAddUser;
|
48
|
+
|
49
|
+
|
50
|
+
/**
|
51
|
+
* This function provides the initialize method for the AddUser class.
|
52
|
+
*
|
53
|
+
* @param argc A count of the number of parameters passed to the method
|
54
|
+
* call.
|
55
|
+
* @param argv A pointer to the start of an array of VALUE entities that
|
56
|
+
* contain the method parameters.
|
57
|
+
* @param self A reference to the AddUser object being initialized.
|
58
|
+
*
|
59
|
+
* @return A reference to the newly initialized AddUser object.
|
60
|
+
*
|
61
|
+
*/
|
62
|
+
VALUE initializeAddUser(int argc, VALUE *argv, VALUE self)
|
63
|
+
{
|
64
|
+
VALUE username = Qnil,
|
65
|
+
password = Qnil,
|
66
|
+
first = Qnil,
|
67
|
+
middle = Qnil,
|
68
|
+
last = Qnil,
|
69
|
+
value = Qnil;
|
70
|
+
int length = 0;
|
71
|
+
|
72
|
+
/* Check that sufficient parameters have been supplied. */
|
73
|
+
if(argc < 2)
|
74
|
+
{
|
75
|
+
rb_raise(rb_eArgError, "Wrong number of arguments (%d for %d).", argc, 2);
|
76
|
+
}
|
77
|
+
|
78
|
+
username = rb_funcall(argv[0], rb_intern("to_s"), 0);
|
79
|
+
password = rb_funcall(argv[1], rb_intern("to_s"), 0);
|
80
|
+
if(argc > 2)
|
81
|
+
{
|
82
|
+
first= rb_funcall(argv[2], rb_intern("to_s"), 0);
|
83
|
+
if(argc > 3)
|
84
|
+
{
|
85
|
+
middle = rb_funcall(argv[3], rb_intern("to_s"), 0);
|
86
|
+
if(argc > 4)
|
87
|
+
{
|
88
|
+
last = rb_funcall(argv[4], rb_intern("to_s"), 0);
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
|
93
|
+
/* Check that the parameters are valid. */
|
94
|
+
value = rb_funcall(username, rb_intern("length"), 0);
|
95
|
+
length = TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value);
|
96
|
+
if(length < 1 || length > 31)
|
97
|
+
{
|
98
|
+
rb_fireruby_raise(NULL,
|
99
|
+
"Invalid user name specified. A user name must not be "\
|
100
|
+
"blank and may have no more than 31 characters.");
|
101
|
+
}
|
102
|
+
|
103
|
+
value = rb_funcall(password, rb_intern("length"), 0);
|
104
|
+
length = TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value);
|
105
|
+
if(length < 1 || length > 31)
|
106
|
+
{
|
107
|
+
rb_fireruby_raise(NULL,
|
108
|
+
"Invalid password specified. A user password must not "\
|
109
|
+
"be blank and may have no more than 31 characters.");
|
110
|
+
}
|
111
|
+
|
112
|
+
/* Assign class values. */
|
113
|
+
rb_iv_set(self, "@user_name", username);
|
114
|
+
rb_iv_set(self, "@password", password);
|
115
|
+
rb_iv_set(self, "@first_name", first);
|
116
|
+
rb_iv_set(self, "@middle_name", middle);
|
117
|
+
rb_iv_set(self, "@last_name", last);
|
118
|
+
|
119
|
+
return(self);
|
120
|
+
}
|
121
|
+
|
122
|
+
|
123
|
+
/**
|
124
|
+
* This function provides the user_name attribute accessor for the AddUser
|
125
|
+
* class.
|
126
|
+
*
|
127
|
+
* @param self A reference to the AddUser object to make the call on.
|
128
|
+
*
|
129
|
+
* @return A reference to the attribute value for the object.
|
130
|
+
*
|
131
|
+
*/
|
132
|
+
VALUE getUserName(VALUE self)
|
133
|
+
{
|
134
|
+
return(rb_iv_get(self, "@user_name"));
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
/**
|
139
|
+
* This function provides the user_name attribute mutator for the AddUser class.
|
140
|
+
*
|
141
|
+
* @param self A reference to the AddUser object to make the call on.
|
142
|
+
* @param setting The new value for the attribute.
|
143
|
+
*
|
144
|
+
* @return A reference to the newly update AddUser object.
|
145
|
+
*
|
146
|
+
*/
|
147
|
+
VALUE setUserName(VALUE self, VALUE setting)
|
148
|
+
{
|
149
|
+
VALUE actual = rb_funcall(setting, rb_intern("to_s"), 0),
|
150
|
+
value = rb_funcall(actual, rb_intern("length"), 0);
|
151
|
+
int length = 0;
|
152
|
+
|
153
|
+
length = TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value);
|
154
|
+
if(length < 1 || length > 31)
|
155
|
+
{
|
156
|
+
rb_fireruby_raise(NULL,
|
157
|
+
"Invalid user name specified. A user name must not be "\
|
158
|
+
"blank and may have no more than 31 characters.");
|
159
|
+
}
|
160
|
+
rb_iv_set(self, "@user_name", actual);
|
161
|
+
|
162
|
+
return(self);
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
/**
|
167
|
+
* This function provides the password attribute accessor for the AddUser
|
168
|
+
* class.
|
169
|
+
*
|
170
|
+
* @param self A reference to the AddUser object to make the call on.
|
171
|
+
*
|
172
|
+
* @return A reference to the attribute value for the object.
|
173
|
+
*
|
174
|
+
*/
|
175
|
+
VALUE getUserPassword(VALUE self)
|
176
|
+
{
|
177
|
+
return(rb_iv_get(self, "@password"));
|
178
|
+
}
|
179
|
+
|
180
|
+
|
181
|
+
/**
|
182
|
+
* This function provides the password attribute mutator for the AddUser class.
|
183
|
+
*
|
184
|
+
* @param self A reference to the AddUser object to make the call on.
|
185
|
+
* @param setting The new value for the attribute.
|
186
|
+
*
|
187
|
+
* @return A reference to the newly update AddUser object.
|
188
|
+
*
|
189
|
+
*/
|
190
|
+
VALUE setUserPassword(VALUE self, VALUE setting)
|
191
|
+
{
|
192
|
+
VALUE actual = rb_funcall(setting, rb_intern("to_s"), 0),
|
193
|
+
value = rb_funcall(actual, rb_intern("length"), 0);
|
194
|
+
int length = 0;
|
195
|
+
|
196
|
+
length = TYPE(value) == T_FIXNUM ? FIX2INT(value) : NUM2INT(value);
|
197
|
+
if(length < 1 || length > 31)
|
198
|
+
{
|
199
|
+
rb_fireruby_raise(NULL,
|
200
|
+
"Invalid password specified. A user password must not "\
|
201
|
+
"be blank and may have no more than 31 characters.");
|
202
|
+
}
|
203
|
+
rb_iv_set(self, "@password", actual);
|
204
|
+
|
205
|
+
return(self);
|
206
|
+
}
|
207
|
+
|
208
|
+
|
209
|
+
/**
|
210
|
+
* This function provides the first_name attribute accessor for the AddUser
|
211
|
+
* class.
|
212
|
+
*
|
213
|
+
* @param self A reference to the AddUser object to make the call on.
|
214
|
+
*
|
215
|
+
* @return A reference to the attribute value for the object.
|
216
|
+
*
|
217
|
+
*/
|
218
|
+
VALUE getUserFirstName(VALUE self)
|
219
|
+
{
|
220
|
+
return(rb_iv_get(self, "@first_name"));
|
221
|
+
}
|
222
|
+
|
223
|
+
|
224
|
+
/**
|
225
|
+
* This function provides the first_name attribute mutator for the AddUser
|
226
|
+
* class.
|
227
|
+
*
|
228
|
+
* @param self A reference to the AddUser object to make the call on.
|
229
|
+
* @param setting The new value for the attribute.
|
230
|
+
*
|
231
|
+
* @return A reference to the newly update AddUser object.
|
232
|
+
*
|
233
|
+
*/
|
234
|
+
VALUE setUserFirstName(VALUE self, VALUE setting)
|
235
|
+
{
|
236
|
+
rb_iv_set(self, "@first_name", setting);
|
237
|
+
return(self);
|
238
|
+
}
|
239
|
+
|
240
|
+
|
241
|
+
/**
|
242
|
+
* This function provides the middle_name attribute accessor for the AddUser
|
243
|
+
* class.
|
244
|
+
*
|
245
|
+
* @param self A reference to the AddUser object to make the call on.
|
246
|
+
*
|
247
|
+
* @return A reference to the attribute value for the object.
|
248
|
+
*
|
249
|
+
*/
|
250
|
+
VALUE getUserMiddleName(VALUE self)
|
251
|
+
{
|
252
|
+
return(rb_iv_get(self, "@middle_name"));
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
/**
|
257
|
+
* This function provides the middle_name attribute mutator for the AddUser
|
258
|
+
* class.
|
259
|
+
*
|
260
|
+
* @param self A reference to the AddUser object to make the call on.
|
261
|
+
* @param setting The new value for the attribute.
|
262
|
+
*
|
263
|
+
* @return A reference to the newly update AddUser object.
|
264
|
+
*
|
265
|
+
*/
|
266
|
+
VALUE setUserMiddleName(VALUE self, VALUE setting)
|
267
|
+
{
|
268
|
+
rb_iv_set(self, "@middle_name", setting);
|
269
|
+
return(self);
|
270
|
+
}
|
271
|
+
|
272
|
+
|
273
|
+
/**
|
274
|
+
* This function provides the last_name attribute accessor for the AddUser
|
275
|
+
* class.
|
276
|
+
*
|
277
|
+
* @param self A reference to the AddUser object to make the call on.
|
278
|
+
*
|
279
|
+
* @return A reference to the attribute value for the object.
|
280
|
+
*
|
281
|
+
*/
|
282
|
+
VALUE getUserLastName(VALUE self)
|
283
|
+
{
|
284
|
+
return(rb_iv_get(self, "@last_name"));
|
285
|
+
}
|
286
|
+
|
287
|
+
|
288
|
+
/**
|
289
|
+
* This function provides the last_name attribute mutator for the AddUser
|
290
|
+
* class.
|
291
|
+
*
|
292
|
+
* @param self A reference to the AddUser object to make the call on.
|
293
|
+
* @param setting The new value for the attribute.
|
294
|
+
*
|
295
|
+
* @return A reference to the newly update AddUser object.
|
296
|
+
*
|
297
|
+
*/
|
298
|
+
VALUE setUserLastName(VALUE self, VALUE setting)
|
299
|
+
{
|
300
|
+
rb_iv_set(self, "@last_name", setting);
|
301
|
+
return(self);
|
302
|
+
}
|
303
|
+
|
304
|
+
|
305
|
+
/**
|
306
|
+
* This function provides the execute method for the AddUser class.
|
307
|
+
*
|
308
|
+
* @param self A reference to the AddUser object to be executed.
|
309
|
+
* @param manager A reference to the ServiceManager that will be used to
|
310
|
+
* execute the task.
|
311
|
+
*
|
312
|
+
* @return A reference to the AddUser object executed.
|
313
|
+
*
|
314
|
+
*/
|
315
|
+
VALUE executeAddUser(VALUE self, VALUE manager)
|
316
|
+
{
|
317
|
+
ManagerHandle *handle = NULL;
|
318
|
+
char *buffer = NULL;
|
319
|
+
short length = 0;
|
320
|
+
ISC_STATUS status[20];
|
321
|
+
|
322
|
+
/* Check that the service manager is connected. */
|
323
|
+
Data_Get_Struct(manager, ManagerHandle, handle);
|
324
|
+
if(handle->handle == 0)
|
325
|
+
{
|
326
|
+
rb_fireruby_raise(NULL,
|
327
|
+
"Add user error. Service manager not connected.");
|
328
|
+
}
|
329
|
+
|
330
|
+
createAddUserBuffer(self, &buffer, &length);
|
331
|
+
|
332
|
+
/* Start the service request. */
|
333
|
+
if(isc_service_start(status, &handle->handle, NULL, length, buffer))
|
334
|
+
{
|
335
|
+
free(buffer);
|
336
|
+
rb_fireruby_raise(status, "Error adding user.");
|
337
|
+
}
|
338
|
+
free(buffer);
|
339
|
+
|
340
|
+
return(self);
|
341
|
+
}
|
342
|
+
|
343
|
+
|
344
|
+
/**
|
345
|
+
* This function provides the execute method for the AddUser class.
|
346
|
+
*
|
347
|
+
* @param self A reference to the AddUser object to generate the buffer for.
|
348
|
+
* @param buffer A pointer to a pointer that will be set to contain the
|
349
|
+
* buffer contents.
|
350
|
+
* @param length A pointer to a short integer that will be assigned the length
|
351
|
+
* of the buffer.
|
352
|
+
*
|
353
|
+
*/
|
354
|
+
void createAddUserBuffer(VALUE self, char **buffer, short *length)
|
355
|
+
{
|
356
|
+
VALUE value = Qnil,
|
357
|
+
first = Qnil,
|
358
|
+
middle = Qnil,
|
359
|
+
last = Qnil;
|
360
|
+
char *offset = NULL;
|
361
|
+
int number = 0;
|
362
|
+
|
363
|
+
/* Calculate the required buffer length. */
|
364
|
+
*length = 1;
|
365
|
+
*length += strlen(STR2CSTR(rb_iv_get(self, "@user_name"))) + 3;
|
366
|
+
*length += strlen(STR2CSTR(rb_iv_get(self, "@password"))) + 3;
|
367
|
+
|
368
|
+
value = rb_iv_get(self, "@first_name");
|
369
|
+
if(value != Qnil)
|
370
|
+
{
|
371
|
+
first = rb_funcall(value, rb_intern("to_s"), 0);
|
372
|
+
*length += strlen(STR2CSTR(first)) + 3;
|
373
|
+
}
|
374
|
+
|
375
|
+
value = rb_iv_get(self, "@middle_name");
|
376
|
+
if(value != Qnil)
|
377
|
+
{
|
378
|
+
middle = rb_funcall(value, rb_intern("to_s"), 0);
|
379
|
+
*length += strlen(STR2CSTR(middle)) + 3;
|
380
|
+
}
|
381
|
+
|
382
|
+
value = rb_iv_get(self, "@last_name");
|
383
|
+
if(value != Qnil)
|
384
|
+
{
|
385
|
+
last = rb_funcall(value, rb_intern("to_s"), 0);
|
386
|
+
*length += strlen(STR2CSTR(last)) + 3;
|
387
|
+
}
|
388
|
+
|
389
|
+
/* Create and populate the buffer. */
|
390
|
+
offset = *buffer = ALLOC_N(char, *length);
|
391
|
+
if(*buffer == NULL)
|
392
|
+
{
|
393
|
+
rb_raise(rb_eNoMemError,
|
394
|
+
"Memory allocation error preparing to add user.");
|
395
|
+
}
|
396
|
+
memset(*buffer, 0, *length);
|
397
|
+
|
398
|
+
*offset++ = isc_action_svc_add_user;
|
399
|
+
|
400
|
+
*offset++ = isc_spb_sec_username;
|
401
|
+
value = rb_iv_get(self, "@user_name");
|
402
|
+
number = strlen(STR2CSTR(value));
|
403
|
+
ADD_SPB_LENGTH(offset, number);
|
404
|
+
memcpy(offset, STR2CSTR(value), number);
|
405
|
+
offset += number;
|
406
|
+
|
407
|
+
*offset++ = isc_spb_sec_password;
|
408
|
+
value = rb_iv_get(self, "@password");
|
409
|
+
number = strlen(STR2CSTR(value));
|
410
|
+
ADD_SPB_LENGTH(offset, number);
|
411
|
+
memcpy(offset, STR2CSTR(value), number);
|
412
|
+
offset += number;
|
413
|
+
|
414
|
+
if(first != Qnil)
|
415
|
+
{
|
416
|
+
*offset++ = isc_spb_sec_firstname;
|
417
|
+
number = strlen(STR2CSTR(first));
|
418
|
+
ADD_SPB_LENGTH(offset, number);
|
419
|
+
memcpy(offset, STR2CSTR(first), number);
|
420
|
+
offset += number;
|
421
|
+
}
|
422
|
+
|
423
|
+
if(middle != Qnil)
|
424
|
+
{
|
425
|
+
*offset++ = isc_spb_sec_middlename;
|
426
|
+
number = strlen(STR2CSTR(middle));
|
427
|
+
ADD_SPB_LENGTH(offset, number);
|
428
|
+
memcpy(offset, STR2CSTR(middle), number);
|
429
|
+
offset += number;
|
430
|
+
}
|
431
|
+
|
432
|
+
if(last != Qnil)
|
433
|
+
{
|
434
|
+
*offset++ = isc_spb_sec_lastname;
|
435
|
+
number = strlen(STR2CSTR(last));
|
436
|
+
ADD_SPB_LENGTH(offset, number);
|
437
|
+
memcpy(offset, STR2CSTR(last), number);
|
438
|
+
offset += number;
|
439
|
+
}
|
440
|
+
}
|
441
|
+
|
442
|
+
|
443
|
+
/**
|
444
|
+
* This function initialize the AddUser class in the Ruby environment.
|
445
|
+
*
|
446
|
+
* @param module The module to create the new class definition under.
|
447
|
+
*
|
448
|
+
*/
|
449
|
+
void Init_AddUser(VALUE module)
|
450
|
+
{
|
451
|
+
cAddUser = rb_define_class_under(module, "AddUser", rb_cObject);
|
452
|
+
rb_define_method(cAddUser, "initialize", initializeAddUser, -1);
|
453
|
+
rb_define_method(cAddUser, "user_name", getUserName, 0);
|
454
|
+
rb_define_method(cAddUser, "user_name=", setUserName, 1);
|
455
|
+
rb_define_method(cAddUser, "password", getUserPassword, 0);
|
456
|
+
rb_define_method(cAddUser, "password=", setUserPassword, 1);
|
457
|
+
rb_define_method(cAddUser, "first_name", getUserFirstName, 0);
|
458
|
+
rb_define_method(cAddUser, "first_name=", setUserFirstName, 1);
|
459
|
+
rb_define_method(cAddUser, "middle_name", getUserMiddleName, 0);
|
460
|
+
rb_define_method(cAddUser, "middle_name=", setUserMiddleName, 1);
|
461
|
+
rb_define_method(cAddUser, "last_name", getUserLastName, 0);
|
462
|
+
rb_define_method(cAddUser, "last_name=", setUserLastName, 1);
|
463
|
+
rb_define_method(cAddUser, "execute", executeAddUser, 1);
|
464
|
+
}
|