rubyfb 0.5.5 → 0.5.6

Sign up to get free protection for your applications and to get access to all the features.
data/ext/Row.h CHANGED
@@ -3,20 +3,20 @@
3
3
  *----------------------------------------------------------------------------*/
4
4
  /**
5
5
  * Copyright � Peter Wood, 2005
6
- *
6
+ *
7
7
  * The contents of this file are subject to the Mozilla Public License Version
8
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
9
+ * License. You may obtain a copy of the License at
10
10
  *
11
11
  * http://www.mozilla.org/MPL/
12
- *
12
+ *
13
13
  * Software distributed under the License is distributed on an "AS IS" basis,
14
14
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
15
15
  * the specificlanguage governing rights and limitations under the License.
16
- *
16
+ *
17
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
18
+ *
19
+ * The Initial Developer of the Original Code is Peter Wood. All Rights
20
20
  * Reserved.
21
21
  *
22
22
  * @author Peter Wood
@@ -25,31 +25,30 @@
25
25
  #ifndef FIRERUBY_ROW_H
26
26
  #define FIRERUBY_ROW_H
27
27
 
28
- /* Includes. */
28
+ /* Includes. */
29
29
  #ifndef RUBY_H_INCLUDED
30
30
  #include "ruby.h"
31
31
  #define RUBY_H_INCLUDED
32
32
  #endif
33
-
34
- /* Type definitions. */
35
- typedef struct
36
- {
37
- char name[32],
38
- alias[32];
39
- VALUE value,
40
- type;
41
- } ColumnHandle;
42
-
43
- typedef struct
44
- {
45
- unsigned int size,
46
- number;
47
- ColumnHandle *columns;
48
- } RowHandle;
49
-
50
- /* Function prototypes. */
51
- void Init_Row(VALUE);
52
- void freeRow(void *);
53
- VALUE rb_row_new(VALUE, VALUE, VALUE);
33
+
34
+ /* Type definitions. */
35
+ typedef struct {
36
+ char name[32],
37
+ alias[32];
38
+ VALUE value,
39
+ type,
40
+ scale;
41
+ } ColumnHandle;
42
+
43
+ typedef struct {
44
+ unsigned int size,
45
+ number;
46
+ ColumnHandle *columns;
47
+ } RowHandle;
48
+
49
+ /* Function prototypes. */
50
+ void Init_Row(VALUE);
51
+ void freeRow(void *);
52
+ VALUE rb_row_new(VALUE, VALUE, VALUE);
54
53
 
55
54
  #endif // FIRERUBY_ROW_H
data/ext/ServiceManager.c CHANGED
@@ -48,20 +48,18 @@ VALUE cServiceManager;
48
48
  * @return A reference to the newly allocated ServiceManager object.
49
49
  *
50
50
  */
51
- VALUE allocateServiceManager(VALUE klass)
52
- {
53
- VALUE instance = Qnil;
54
- ManagerHandle *manager = ALLOC(ManagerHandle);
55
-
56
- if(manager == NULL)
57
- {
58
- rb_raise(rb_eNoMemError,
59
- "Memory allocation failure creating a service manager.");
60
- }
61
- manager->handle = NULL;
62
- instance = Data_Wrap_Struct(klass, NULL, serviceManagerFree, manager);
63
-
64
- return(instance);
51
+ VALUE allocateServiceManager(VALUE klass) {
52
+ VALUE instance = Qnil;
53
+ ManagerHandle *manager = ALLOC(ManagerHandle);
54
+
55
+ if(manager == NULL) {
56
+ rb_raise(rb_eNoMemError,
57
+ "Memory allocation failure creating a service manager.");
58
+ }
59
+ manager->handle = NULL;
60
+ instance = Data_Wrap_Struct(klass, NULL, serviceManagerFree, manager);
61
+
62
+ return(instance);
65
63
  }
66
64
 
67
65
 
@@ -72,13 +70,12 @@ VALUE allocateServiceManager(VALUE klass)
72
70
  * @param host The name of the database host for the service manager.
73
71
  *
74
72
  */
75
- VALUE initializeServiceManager(VALUE self, VALUE host)
76
- {
77
- VALUE text = rb_funcall(host, rb_intern("to_s"), 0);
73
+ VALUE initializeServiceManager(VALUE self, VALUE host) {
74
+ VALUE text = rb_funcall(host, rb_intern("to_s"), 0);
78
75
 
79
- rb_iv_set(self, "@host", text);
76
+ rb_iv_set(self, "@host", text);
80
77
 
81
- return(self);
78
+ return(self);
82
79
  }
83
80
 
84
81
 
@@ -94,80 +91,75 @@ VALUE initializeServiceManager(VALUE self, VALUE host)
94
91
  * @return A reference to the newly connected ServiceManager object.
95
92
  *
96
93
  */
97
- VALUE connectServiceManager(VALUE self, VALUE user, VALUE password)
98
- {
99
- ManagerHandle *manager = NULL;
100
- char *buffer = NULL,
101
- *position = NULL,
102
- *text = NULL,
103
- *service = NULL;
104
- short length = 2,
105
- size = 0;
106
- VALUE host = rb_iv_get(self, "@host");
107
- ISC_STATUS status[20];
108
-
109
- Data_Get_Struct(self, ManagerHandle, manager);
110
- if(manager->handle != 0)
111
- {
112
- rb_fireruby_raise(NULL, "Service manager already connected.");
113
- }
114
-
115
- /* Calculate the size of the service parameter buffer. */
116
- length += strlen(StringValuePtr(user)) + 2;
117
- length += strlen(StringValuePtr(password)) + 2;
118
-
119
- /* Create the service parameter buffer. */
120
- position = buffer = ALLOC_N(char, length);
121
- if(position == NULL)
122
- {
123
- rb_raise(rb_eNoMemError,
124
- "Memory allocation failure creating service parameter buffer.");
125
- }
126
- memset(buffer, 0, length);
127
-
128
- /* Populate the service parameter buffer. */
129
- *position++ = isc_spb_version;
130
- *position++ = isc_spb_current_version;
131
-
132
- text = StringValuePtr(user);
133
- size = strlen(text);
134
- *position++ = isc_spb_user_name;
135
- *position++ = size;
136
- strncpy(position, text, size);
137
- position += size;
138
-
139
- text = StringValuePtr(password);
140
- size = strlen(text);
141
- *position++ = isc_spb_password;
142
- *position++ = size;
143
- strncpy(position, text, size);
144
-
145
- /* Create the service name. */
146
- size = strlen(StringValuePtr(host)) + 13;
147
- service = ALLOC_N(char, size);
148
- if(service == NULL)
149
- {
150
- free(buffer);
151
- rb_raise(rb_eNoMemError,
152
- "Memory allocation failure service manager service name.");
153
- }
154
- memset(service, 0, size);
155
- sprintf(service, "%s:service_mgr", StringValuePtr(host));
156
-
157
- /* Make the attachment call. */
158
- if(isc_service_attach(status, 0, service, &manager->handle, length,
159
- buffer))
160
- {
161
- free(buffer);
162
- free(service);
163
- rb_fireruby_raise(status, "Error connecting service manager.");
164
- }
165
-
166
- /* Clean up. */
167
- free(buffer);
168
- free(service);
169
-
170
- return(self);
94
+ VALUE connectServiceManager(VALUE self, VALUE user, VALUE password) {
95
+ ManagerHandle *manager = NULL;
96
+ char *buffer = NULL,
97
+ *position = NULL,
98
+ *text = NULL,
99
+ *service = NULL;
100
+ short length = 2,
101
+ size = 0;
102
+ VALUE host = rb_iv_get(self, "@host");
103
+ ISC_STATUS status[ISC_STATUS_LENGTH];
104
+
105
+ Data_Get_Struct(self, ManagerHandle, manager);
106
+ if(manager->handle != 0) {
107
+ rb_fireruby_raise(NULL, "Service manager already connected.");
108
+ }
109
+
110
+ /* Calculate the size of the service parameter buffer. */
111
+ length += strlen(StringValuePtr(user)) + 2;
112
+ length += strlen(StringValuePtr(password)) + 2;
113
+
114
+ /* Create the service parameter buffer. */
115
+ position = buffer = ALLOC_N(char, length);
116
+ if(position == NULL) {
117
+ rb_raise(rb_eNoMemError,
118
+ "Memory allocation failure creating service parameter buffer.");
119
+ }
120
+ memset(buffer, 0, length);
121
+
122
+ /* Populate the service parameter buffer. */
123
+ *position++ = isc_spb_version;
124
+ *position++ = isc_spb_current_version;
125
+
126
+ text = StringValuePtr(user);
127
+ size = strlen(text);
128
+ *position++ = isc_spb_user_name;
129
+ *position++ = size;
130
+ strncpy(position, text, size);
131
+ position += size;
132
+
133
+ text = StringValuePtr(password);
134
+ size = strlen(text);
135
+ *position++ = isc_spb_password;
136
+ *position++ = size;
137
+ strncpy(position, text, size);
138
+
139
+ /* Create the service name. */
140
+ size = strlen(StringValuePtr(host)) + 13;
141
+ service = ALLOC_N(char, size);
142
+ if(service == NULL) {
143
+ free(buffer);
144
+ rb_raise(rb_eNoMemError,
145
+ "Memory allocation failure service manager service name.");
146
+ }
147
+ memset(service, 0, size);
148
+ sprintf(service, "%s:service_mgr", StringValuePtr(host));
149
+
150
+ /* Make the attachment call. */
151
+ if(isc_service_attach(status, 0, service, &manager->handle, length,
152
+ buffer)) {
153
+ free(buffer);
154
+ free(service);
155
+ rb_fireruby_raise(status, "Error connecting service manager.");
156
+ }
157
+
158
+ /* Clean up. */
159
+ free(buffer);
160
+ free(service);
161
+
162
+ return(self);
171
163
  }
172
164
 
173
165
 
@@ -179,23 +171,20 @@ VALUE connectServiceManager(VALUE self, VALUE user, VALUE password)
179
171
  * @return A reference to the disconnected ServiceManager object.
180
172
  *
181
173
  */
182
- VALUE disconnectServiceManager(VALUE self)
183
- {
184
- ManagerHandle *manager = NULL;
185
-
186
- Data_Get_Struct(self, ManagerHandle, manager);
187
- if(manager->handle != 0)
188
- {
189
- ISC_STATUS status[20];
190
-
191
- if(isc_service_detach(status, &manager->handle))
192
- {
193
- rb_fireruby_raise(status, "Error disconnecting service manager.");
194
- }
195
- manager->handle = 0;
196
- }
197
-
198
- return(self);
174
+ VALUE disconnectServiceManager(VALUE self) {
175
+ ManagerHandle *manager = NULL;
176
+
177
+ Data_Get_Struct(self, ManagerHandle, manager);
178
+ if(manager->handle != 0) {
179
+ ISC_STATUS status[ISC_STATUS_LENGTH];
180
+
181
+ if(isc_service_detach(status, &manager->handle)) {
182
+ rb_fireruby_raise(status, "Error disconnecting service manager.");
183
+ }
184
+ manager->handle = 0;
185
+ }
186
+
187
+ return(self);
199
188
  }
200
189
 
201
190
 
@@ -207,18 +196,16 @@ VALUE disconnectServiceManager(VALUE self)
207
196
  * @return True if the manager is connected, false otherwise.
208
197
  *
209
198
  */
210
- VALUE isServiceManagerConnected(VALUE self)
211
- {
212
- VALUE result = Qfalse;
213
- ManagerHandle *manager = NULL;
214
-
215
- Data_Get_Struct(self, ManagerHandle, manager);
216
- if(manager->handle != 0)
217
- {
218
- result = Qtrue;
219
- }
220
-
221
- return(result);
199
+ VALUE isServiceManagerConnected(VALUE self) {
200
+ VALUE result = Qfalse;
201
+ ManagerHandle *manager = NULL;
202
+
203
+ Data_Get_Struct(self, ManagerHandle, manager);
204
+ if(manager->handle != 0) {
205
+ result = Qtrue;
206
+ }
207
+
208
+ return(result);
222
209
  }
223
210
 
224
211
 
@@ -235,19 +222,16 @@ VALUE isServiceManagerConnected(VALUE self)
235
222
  * @return A reference to the ServiceManager class.
236
223
  *
237
224
  */
238
- VALUE executeServiceTasks(int argc, VALUE *argv, VALUE self)
239
- {
240
- if(argc > 0)
241
- {
242
- int i;
243
-
244
- for(i = 0; i < argc; i++)
245
- {
246
- rb_funcall(argv[i], rb_intern("execute"), 1, self);
247
- }
248
- }
249
-
250
- return(self);
225
+ VALUE executeServiceTasks(int argc, VALUE *argv, VALUE self) {
226
+ if(argc > 0) {
227
+ int i;
228
+
229
+ for(i = 0; i < argc; i++) {
230
+ rb_funcall(argv[i], rb_intern("execute"), 1, self);
231
+ }
232
+ }
233
+
234
+ return(self);
251
235
  }
252
236
 
253
237
 
@@ -260,20 +244,17 @@ VALUE executeServiceTasks(int argc, VALUE *argv, VALUE self)
260
244
  * ServiceManager being collected.
261
245
  *
262
246
  */
263
- void serviceManagerFree(void *manager)
264
- {
265
- if(manager != NULL)
266
- {
267
- ManagerHandle *handle = (ManagerHandle *)manager;
268
-
269
- if(handle->handle != 0)
270
- {
271
- ISC_STATUS status[20];
272
-
273
- isc_service_detach(status, &handle->handle);
274
- }
275
- free(handle);
276
- }
247
+ void serviceManagerFree(void *manager) {
248
+ if(manager != NULL) {
249
+ ManagerHandle *handle = (ManagerHandle *)manager;
250
+
251
+ if(handle->handle != 0) {
252
+ ISC_STATUS status[ISC_STATUS_LENGTH];
253
+
254
+ isc_service_detach(status, &handle->handle);
255
+ }
256
+ free(handle);
257
+ }
277
258
  }
278
259
 
279
260
 
@@ -287,13 +268,12 @@ void serviceManagerFree(void *manager)
287
268
  * @return A reference to the newly created ServiceManager object.
288
269
  *
289
270
  */
290
- VALUE rb_service_manager_new(VALUE host)
291
- {
292
- VALUE manager = allocateServiceManager(cServiceManager);
271
+ VALUE rb_service_manager_new(VALUE host) {
272
+ VALUE manager = allocateServiceManager(cServiceManager);
293
273
 
294
- initializeServiceManager(manager, host);
274
+ initializeServiceManager(manager, host);
295
275
 
296
- return(manager);
276
+ return(manager);
297
277
  }
298
278
 
299
279
 
@@ -303,14 +283,13 @@ VALUE rb_service_manager_new(VALUE host)
303
283
  * @param module The module to create the new class definition under.
304
284
  *
305
285
  */
306
- void Init_ServiceManager(VALUE module)
307
- {
308
- cServiceManager = rb_define_class_under(module, "ServiceManager", rb_cObject);
309
- rb_define_alloc_func(cServiceManager, allocateServiceManager);
310
- rb_define_method(cServiceManager, "initialize", initializeServiceManager, 1);
311
- rb_define_method(cServiceManager, "initialize_copy", forbidObjectCopy, 1);
312
- rb_define_method(cServiceManager, "connect", connectServiceManager, 2);
313
- rb_define_method(cServiceManager, "disconnect", disconnectServiceManager, 0);
314
- rb_define_method(cServiceManager, "connected?", isServiceManagerConnected, 0);
315
- rb_define_method(cServiceManager, "execute", executeServiceTasks, -1);
286
+ void Init_ServiceManager(VALUE module) {
287
+ cServiceManager = rb_define_class_under(module, "ServiceManager", rb_cObject);
288
+ rb_define_alloc_func(cServiceManager, allocateServiceManager);
289
+ rb_define_method(cServiceManager, "initialize", initializeServiceManager, 1);
290
+ rb_define_method(cServiceManager, "initialize_copy", forbidObjectCopy, 1);
291
+ rb_define_method(cServiceManager, "connect", connectServiceManager, 2);
292
+ rb_define_method(cServiceManager, "disconnect", disconnectServiceManager, 0);
293
+ rb_define_method(cServiceManager, "connected?", isServiceManagerConnected, 0);
294
+ rb_define_method(cServiceManager, "execute", executeServiceTasks, -1);
316
295
  }
data/ext/ServiceManager.h CHANGED
@@ -3,20 +3,20 @@
3
3
  *----------------------------------------------------------------------------*/
4
4
  /**
5
5
  * Copyright � Peter Wood, 2005
6
- *
6
+ *
7
7
  * The contents of this file are subject to the Mozilla Public License Version
8
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
9
+ * License. You may obtain a copy of the License at
10
10
  *
11
11
  * http://www.mozilla.org/MPL/
12
- *
12
+ *
13
13
  * Software distributed under the License is distributed on an "AS IS" basis,
14
14
  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
15
15
  * the specificlanguage governing rights and limitations under the License.
16
- *
16
+ *
17
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
18
+ *
19
+ * The Initial Developer of the Original Code is Peter Wood. All Rights
20
20
  * Reserved.
21
21
  *
22
22
  * @author Peter Wood
@@ -25,7 +25,7 @@
25
25
  #ifndef FIRERUBY_SERVICE_MANAGER_H
26
26
  #define FIRERUBY_SERVICE_MANAGER_H
27
27
 
28
- /* Includes. */
28
+ /* Includes. */
29
29
  #ifndef FIRERUBY_FIRE_RUBY_H
30
30
  #include "FireRuby.h"
31
31
  #endif
@@ -33,16 +33,15 @@
33
33
  #ifndef FIRERUBY_FIRE_RUBY_EXCEPTION_H
34
34
  #include "FireRubyException.h"
35
35
  #endif
36
-
37
- /* Type definitions. */
38
- typedef struct
39
- {
40
- isc_svc_handle handle;
41
- } ManagerHandle;
42
-
43
- /* Function prototypes. */
44
- void Init_ServiceManager(VALUE);
45
- void serviceManagerFree(void *);
46
- VALUE rb_service_manager_new(VALUE);
36
+
37
+ /* Type definitions. */
38
+ typedef struct {
39
+ isc_svc_handle handle;
40
+ } ManagerHandle;
41
+
42
+ /* Function prototypes. */
43
+ void Init_ServiceManager(VALUE);
44
+ void serviceManagerFree(void *);
45
+ VALUE rb_service_manager_new(VALUE);
47
46
 
48
47
  #endif /* FIRERUBY_SERVICE_MANAGER_H */
data/ext/Services.c CHANGED
@@ -45,81 +45,72 @@
45
45
  * or nil if there is no output.
46
46
  *
47
47
  */
48
- VALUE queryService(isc_svc_handle *handle)
49
- {
50
- VALUE result = Qnil;
51
- int size = START_BUFFER_SIZE;
52
- short done = 0;
48
+ VALUE queryService(isc_svc_handle *handle) {
49
+ VALUE result = Qnil;
50
+ int size = START_BUFFER_SIZE;
51
+ short done = 0;
53
52
 
54
- /* Query the service until it has completed. */
55
- while(!done)
56
- {
57
- ISC_STATUS status[20];
58
- char *output = NULL,
59
- *offset = NULL,
60
- *log = NULL,
61
- request[] = {isc_info_svc_to_eof};
62
- short len = 0;
53
+ /* Query the service until it has completed. */
54
+ while(!done) {
55
+ ISC_STATUS status[ISC_STATUS_LENGTH];
56
+ char *output = NULL,
57
+ *offset = NULL,
58
+ *log = NULL,
59
+ request[] = {isc_info_svc_to_eof};
60
+ short len = 0;
63
61
 
64
- /* Allocate the output buffer. */
65
- offset = output = ALLOC_N(char, size);
66
- if(output == NULL)
67
- {
68
- rb_raise(rb_eNoMemError,
69
- "Memory allocation failure querying service status.");
70
- }
71
- memset(output, 0, size);
62
+ /* Allocate the output buffer. */
63
+ offset = output = ALLOC_N(char, size);
64
+ if(output == NULL) {
65
+ rb_raise(rb_eNoMemError,
66
+ "Memory allocation failure querying service status.");
67
+ }
68
+ memset(output, 0, size);
72
69
 
73
- /* Make the service info request. */
74
- done = 1;
75
- if(isc_service_query(status, handle, NULL, 0, NULL, sizeof(request),
76
- request, size, output))
77
- {
78
- free(output);
79
- rb_fireruby_raise(status, "Error querying service status.");
80
- }
70
+ /* Make the service info request. */
71
+ done = 1;
72
+ if(isc_service_query(status, handle, NULL, 0, NULL, sizeof(request),
73
+ request, size, output)) {
74
+ free(output);
75
+ rb_fireruby_raise(status, "Error querying service status.");
76
+ }
81
77
 
82
- do
83
- {
84
- switch(*offset++)
85
- {
86
- case isc_info_svc_to_eof :
87
- len = isc_vax_integer(offset, 2);
88
- offset += 2;
89
- if(len > 0)
90
- {
91
- log = ALLOC_N(char, len + 1);
92
- if(log == NULL)
93
- {
94
- free(output);
95
- rb_raise(rb_eNoMemError,
96
- "Memory allocation failure querying service status.");
97
- }
78
+ do {
79
+ switch(*offset++) {
80
+ case isc_info_svc_to_eof:
81
+ len = isc_vax_integer(offset, 2);
82
+ offset += 2;
83
+ if(len > 0) {
84
+ log = ALLOC_N(char, len + 1);
85
+ if(log == NULL) {
86
+ free(output);
87
+ rb_raise(rb_eNoMemError,
88
+ "Memory allocation failure querying service status.");
89
+ }
98
90
 
99
- memset(log, 0, len + 1);
100
- memcpy(log, offset, len);
91
+ memset(log, 0, len + 1);
92
+ memcpy(log, offset, len);
101
93
 
102
- result = rb_str_new2(log);
103
- free(log);
104
- }
105
- break;
94
+ result = rb_str_new2(log);
95
+ free(log);
96
+ }
97
+ break;
106
98
 
107
- case isc_info_truncated :
108
- done = 0;
109
- size = size * 2;
110
- break;
111
- }
112
- } while(*offset);
99
+ case isc_info_truncated:
100
+ done = 0;
101
+ size = size * 2;
102
+ break;
103
+ }
104
+ } while(*offset);
113
105
 
114
- /* Clean up. */
115
- free(output);
106
+ /* Clean up. */
107
+ free(output);
116
108
 
117
- /* Snooze if we're not done. */
118
- if(!done)
119
- {
120
- rfb_sleep(1);
121
- }
122
- }
109
+ /* Snooze if we're not done. */
110
+ if(!done) {
111
+ rfb_sleep(1);
112
+ }
113
+ }
123
114
 
124
- return(result);
115
+ return(result);
125
116
  }
data/ext/Services.h CHANGED
@@ -25,7 +25,7 @@
25
25
  #ifndef FIRERUBY_SERVICES_H
26
26
  #define FIRERUBY_SERVICES_H
27
27
 
28
- /* Includes. */
28
+ /* Includes. */
29
29
  #ifndef IBASE_H_INCLUDED
30
30
  #include "ibase.h"
31
31
  #define IBASE_H_INCLUDED
@@ -36,7 +36,7 @@
36
36
  #define RUBY_H_INCLUDED
37
37
  #endif
38
38
 
39
- /* Function prototypes. */
40
- VALUE queryService(isc_svc_handle *);
39
+ /* Function prototypes. */
40
+ VALUE queryService(isc_svc_handle *);
41
41
 
42
42
  #endif /* FIRERUBY_SERVICES_H */