WireAPI 0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/amq_connection.c +232 -0
- data/amq_connection.h +5 -0
- data/amq_content.c +533 -0
- data/amq_content.h +7 -0
- data/amq_field_list.c +318 -0
- data/amq_field_list.h +13 -0
- data/amq_session.c +954 -0
- data/amq_session.h +5 -0
- data/amq_types.c +273 -0
- data/amq_types.h +128 -0
- data/amq_wireapi.c +195 -0
- data/extconf.rb +30 -0
- metadata +64 -0
data/amq_session.h
ADDED
data/amq_types.c
ADDED
@@ -0,0 +1,273 @@
|
|
1
|
+
|
2
|
+
#include <ruby.h>
|
3
|
+
#include "amq_types.h"
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
/* session allocator, destructor , accessor */
|
8
|
+
|
9
|
+
|
10
|
+
amq_session_cls* get_amq_session_cls(VALUE rb_obj,int raise) {
|
11
|
+
amq_session_cls *result=0;
|
12
|
+
Data_Get_Struct(rb_obj,amq_session_cls,result);
|
13
|
+
if (raise && !result->session) {
|
14
|
+
rb_raise(rb_amq_error,"Session already destroyed");
|
15
|
+
}
|
16
|
+
if (!rb_obj_is_instance_of(rb_obj, amqp_session)) {
|
17
|
+
rb_raise(rb_eTypeError, "expected an AMQ_Session object");
|
18
|
+
}
|
19
|
+
return result;
|
20
|
+
}
|
21
|
+
|
22
|
+
void free_amq_session_cls( amq_session_cls *obj) {
|
23
|
+
if (obj && obj->session) {
|
24
|
+
amq_client_session_destroy (&(obj->session));
|
25
|
+
obj->session=0;
|
26
|
+
}
|
27
|
+
if (obj)
|
28
|
+
free(obj);
|
29
|
+
}
|
30
|
+
|
31
|
+
VALUE create_amq_session_cls(amq_client_session_t *session) {
|
32
|
+
VALUE rb_session;
|
33
|
+
amq_session_cls *obj=ALLOC(amq_session_cls);
|
34
|
+
obj->session=session;
|
35
|
+
rb_session = Data_Wrap_Struct(amqp_session,0,free_amq_session_cls,obj);
|
36
|
+
return rb_session;
|
37
|
+
}
|
38
|
+
|
39
|
+
|
40
|
+
/* content allocator, destructor , accessor */
|
41
|
+
amq_content_cls* get_amq_content_cls(VALUE rb_obj,int raise) {
|
42
|
+
amq_content_cls *result=0;
|
43
|
+
Data_Get_Struct(rb_obj,amq_content_cls,result);
|
44
|
+
if (raise && !result->content) {
|
45
|
+
rb_raise(rb_amq_error,"Content already destroyed");
|
46
|
+
}
|
47
|
+
if (!rb_obj_is_instance_of(rb_obj, amqp_content)) {
|
48
|
+
rb_raise(rb_eTypeError, "expected an AMQ_ContentBasic object");
|
49
|
+
}
|
50
|
+
return result;
|
51
|
+
}
|
52
|
+
|
53
|
+
void free_amq_content_cls( amq_content_cls *obj) {
|
54
|
+
if (obj && obj->content) {
|
55
|
+
amq_content_basic_unlink(&(obj->content));
|
56
|
+
obj->content=0;
|
57
|
+
}
|
58
|
+
if (obj)
|
59
|
+
free(obj);
|
60
|
+
}
|
61
|
+
|
62
|
+
VALUE create_amq_content_cls(amq_content_basic_t *content) {
|
63
|
+
VALUE rb_content;
|
64
|
+
amq_content_cls *obj=ALLOC(amq_content_cls);
|
65
|
+
obj->content=content;
|
66
|
+
rb_content = Data_Wrap_Struct(amqp_content,0,free_amq_content_cls,obj);
|
67
|
+
return rb_content;
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
/* connection allocator, destructor , accessor */
|
72
|
+
|
73
|
+
amq_connection_cls* get_amq_connection_cls(VALUE rb_obj,int raise) {
|
74
|
+
amq_connection_cls *result=0;
|
75
|
+
Data_Get_Struct(rb_obj,amq_connection_cls,result);
|
76
|
+
if (raise && !result->connection) {
|
77
|
+
rb_raise(rb_amq_error,"Connection already destroyed");
|
78
|
+
}
|
79
|
+
if (!rb_obj_is_instance_of(rb_obj, amqp_connection)) {
|
80
|
+
rb_raise(rb_eTypeError, "expected an AMQ_Connection object");
|
81
|
+
}
|
82
|
+
return result;
|
83
|
+
}
|
84
|
+
|
85
|
+
void free_amq_connection_cls( amq_connection_cls *obj) {
|
86
|
+
if (obj && obj->connection) {
|
87
|
+
amq_client_connection_destroy(&(obj->connection));
|
88
|
+
obj->connection=0;
|
89
|
+
}
|
90
|
+
if (obj)
|
91
|
+
free(obj);
|
92
|
+
}
|
93
|
+
|
94
|
+
VALUE create_amq_connection_cls(amq_client_connection_t *connection) {
|
95
|
+
VALUE rb_connection;
|
96
|
+
amq_connection_cls *obj=ALLOC(amq_connection_cls);
|
97
|
+
obj->connection=connection;
|
98
|
+
rb_connection = Data_Wrap_Struct(amqp_connection,0,free_amq_connection_cls,obj);
|
99
|
+
return rb_connection;
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
/* connection allocator, destructor , accessor */
|
106
|
+
|
107
|
+
amq_auth_cls* get_amq_auth_cls(VALUE rb_obj,VALUE raise) {
|
108
|
+
amq_auth_cls *result=0;
|
109
|
+
Data_Get_Struct(rb_obj,amq_auth_cls,result);
|
110
|
+
if (raise && !result->auth) {
|
111
|
+
rb_raise(rb_amq_error,"Auth_data already destroyed");
|
112
|
+
}
|
113
|
+
if (!rb_obj_is_instance_of(rb_obj, amqp_auth)) {
|
114
|
+
rb_raise(rb_eTypeError, "expected an AMQ_Auth object");
|
115
|
+
}
|
116
|
+
return result;
|
117
|
+
}
|
118
|
+
|
119
|
+
|
120
|
+
void free_amq_auth_cls( amq_auth_cls *obj) {
|
121
|
+
if (obj && obj->auth) {
|
122
|
+
icl_longstr_destroy(&(obj->auth));
|
123
|
+
obj->auth=0;
|
124
|
+
}
|
125
|
+
if (obj)
|
126
|
+
free(obj);
|
127
|
+
}
|
128
|
+
|
129
|
+
|
130
|
+
VALUE create_amq_auth_cls(icl_longstr_t *auth) {
|
131
|
+
VALUE rb_auth;
|
132
|
+
amq_auth_cls *obj=ALLOC(amq_auth_cls);
|
133
|
+
obj->auth=auth;
|
134
|
+
rb_auth = Data_Wrap_Struct(amqp_auth,0,free_amq_auth_cls,obj);
|
135
|
+
return rb_auth;
|
136
|
+
}
|
137
|
+
|
138
|
+
|
139
|
+
/* int6_t allocator, destructor , accessor */
|
140
|
+
amq_int64_cls* get_amq_int64_cls(VALUE rb_obj) {
|
141
|
+
amq_int64_cls *result=0;
|
142
|
+
if (!rb_obj_is_instance_of(rb_obj, amqp_int64)) {
|
143
|
+
rb_raise(rb_eTypeError, "expected an AMQ_int64 object");
|
144
|
+
}
|
145
|
+
Data_Get_Struct(rb_obj,amq_int64_cls,result);
|
146
|
+
return result;
|
147
|
+
}
|
148
|
+
|
149
|
+
void free_amq_int64_cls( amq_int64_cls *obj) {
|
150
|
+
if (obj && obj->value) {
|
151
|
+
obj->value=0;
|
152
|
+
}
|
153
|
+
if (obj)
|
154
|
+
free(obj);
|
155
|
+
}
|
156
|
+
|
157
|
+
VALUE create_amq_int64_cls(int64_t int64) {
|
158
|
+
VALUE rb_int64;
|
159
|
+
amq_int64_cls *obj=ALLOC(amq_int64_cls);
|
160
|
+
obj->value=int64;
|
161
|
+
rb_int64 = Data_Wrap_Struct(amqp_int64,0,free_amq_int64_cls,obj);
|
162
|
+
return rb_int64;
|
163
|
+
}
|
164
|
+
|
165
|
+
|
166
|
+
int VALUE2bool (VALUE v,const char *msg) {
|
167
|
+
if (v==Qtrue)
|
168
|
+
return 1;
|
169
|
+
if (v==Qfalse)
|
170
|
+
return 0;
|
171
|
+
char total_msg[250];
|
172
|
+
if (TYPE(v)!= T_ICLASS) {
|
173
|
+
sprintf(total_msg,"%s (%x)",msg,TYPE(v));
|
174
|
+
} else {
|
175
|
+
sprintf(total_msg,"%s (%s)",msg,rb_obj_classname(v));
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
rb_raise(rb_amq_error,total_msg);
|
180
|
+
return 0;
|
181
|
+
}
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
/* connection allocator, destructor , accessor */
|
196
|
+
|
197
|
+
amq_field_list_cls* get_amq_field_list_cls(VALUE rb_obj,VALUE raise) {
|
198
|
+
amq_field_list_cls *result=0;
|
199
|
+
Data_Get_Struct(rb_obj,amq_field_list_cls,result);
|
200
|
+
if (raise && !result->field_list) {
|
201
|
+
rb_raise(rb_amq_error,"field_list already destroyed");
|
202
|
+
}
|
203
|
+
if (!rb_obj_is_instance_of(rb_obj, amqp_field_list)) {
|
204
|
+
rb_raise(rb_eTypeError, "expected an AMQ_FieldList");
|
205
|
+
}
|
206
|
+
|
207
|
+
return result;
|
208
|
+
}
|
209
|
+
|
210
|
+
|
211
|
+
void free_amq_field_list_cls( amq_field_list_cls *obj) {
|
212
|
+
if (obj && obj->field_list) {
|
213
|
+
asl_field_list_destroy (&(obj->field_list));
|
214
|
+
obj->field_list=0;
|
215
|
+
}
|
216
|
+
if (obj)
|
217
|
+
free(obj);
|
218
|
+
}
|
219
|
+
|
220
|
+
|
221
|
+
VALUE create_amq_field_list_cls(asl_field_list_t *field_list) {
|
222
|
+
VALUE rb_field_list;
|
223
|
+
amq_field_list_cls *obj=ALLOC(amq_field_list_cls);
|
224
|
+
obj->field_list=field_list;
|
225
|
+
rb_field_list = Data_Wrap_Struct(amqp_field_list,0,free_amq_field_list_cls,obj);
|
226
|
+
return rb_field_list;
|
227
|
+
}
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
|
232
|
+
/* rb_wireapi allocator, destructor , accessor */
|
233
|
+
static int wire_api_ref_counter=0;
|
234
|
+
static int wire_api_instance_counter=0;
|
235
|
+
|
236
|
+
amq_wire_api_cls* get_amq_wire_api_cls(VALUE rb_obj,VALUE raise) {
|
237
|
+
amq_wire_api_cls *result=0;
|
238
|
+
Data_Get_Struct(rb_obj,amq_wire_api_cls,result);
|
239
|
+
if (raise && !result) {
|
240
|
+
rb_raise(rb_amq_error,"WireAPI already destroyed");
|
241
|
+
}
|
242
|
+
if (!rb_obj_is_instance_of(rb_obj, rb_wireapi)) {
|
243
|
+
rb_raise(rb_eTypeError, "expected an WireAPI object");
|
244
|
+
}
|
245
|
+
return result;
|
246
|
+
}
|
247
|
+
|
248
|
+
|
249
|
+
void free_amq_wire_api_cls( amq_wire_api_cls *obj) {
|
250
|
+
if (obj && obj->instance_id) {
|
251
|
+
obj->instance_id=0;
|
252
|
+
--wire_api_ref_counter;
|
253
|
+
if (wire_api_ref_counter<=0) {
|
254
|
+
icl_system_terminate ();
|
255
|
+
}
|
256
|
+
}
|
257
|
+
if (obj)
|
258
|
+
free(obj);
|
259
|
+
}
|
260
|
+
|
261
|
+
|
262
|
+
VALUE create_amq_wire_api_cls() {
|
263
|
+
VALUE rb_wapi;
|
264
|
+
amq_wire_api_cls *obj=ALLOC(amq_wire_api_cls);
|
265
|
+
// obj->field_list=field_list;
|
266
|
+
rb_wapi = Data_Wrap_Struct(rb_wireapi,0,free_amq_wire_api_cls,obj);
|
267
|
+
if (wire_api_ref_counter==0) {
|
268
|
+
icl_system_initialise (0,0);
|
269
|
+
}
|
270
|
+
++wire_api_ref_counter;
|
271
|
+
obj->instance_id=++wire_api_instance_counter;
|
272
|
+
return rb_wapi;
|
273
|
+
}
|
data/amq_types.h
ADDED
@@ -0,0 +1,128 @@
|
|
1
|
+
#ifndef AMQ_TYPES_HEADER
|
2
|
+
#define AMQ_TYPES_HEADER
|
3
|
+
|
4
|
+
#include "asl.h"
|
5
|
+
#include "amq_client_connection.h"
|
6
|
+
#include "amq_client_session.h"
|
7
|
+
#include "amq_client_agent.h"
|
8
|
+
#include "amq_exchange.h"
|
9
|
+
|
10
|
+
extern VALUE amqp_content;
|
11
|
+
|
12
|
+
extern VALUE rb_wireapi;
|
13
|
+
|
14
|
+
extern VALUE amqp_connection;
|
15
|
+
|
16
|
+
extern VALUE amqp_session;
|
17
|
+
|
18
|
+
extern VALUE amqp_auth;
|
19
|
+
|
20
|
+
extern VALUE amqp_field_list;
|
21
|
+
|
22
|
+
extern VALUE rb_amq_error;
|
23
|
+
|
24
|
+
extern VALUE rb_amq_server_error;
|
25
|
+
|
26
|
+
extern VALUE amqp_int64;
|
27
|
+
|
28
|
+
|
29
|
+
struct _amq_session_cls {
|
30
|
+
amq_client_session_t *session;
|
31
|
+
};
|
32
|
+
|
33
|
+
typedef struct _amq_session_cls amq_session_cls;
|
34
|
+
|
35
|
+
/* */
|
36
|
+
|
37
|
+
struct _amq_content_cls {
|
38
|
+
amq_content_basic_t *content;
|
39
|
+
};
|
40
|
+
|
41
|
+
typedef struct _amq_content_cls amq_content_cls;
|
42
|
+
/* */
|
43
|
+
|
44
|
+
struct _amq_connection_cls {
|
45
|
+
amq_client_connection_t *connection;
|
46
|
+
};
|
47
|
+
|
48
|
+
typedef struct _amq_connection_cls amq_connection_cls;
|
49
|
+
|
50
|
+
|
51
|
+
|
52
|
+
struct _amq_auth_cls {
|
53
|
+
icl_longstr_t *auth;
|
54
|
+
};
|
55
|
+
|
56
|
+
typedef struct _amq_auth_cls amq_auth_cls;
|
57
|
+
|
58
|
+
struct _amq_int64_cls {
|
59
|
+
int64_t value;
|
60
|
+
};
|
61
|
+
|
62
|
+
typedef struct _amq_int64_cls amq_int64_cls;
|
63
|
+
|
64
|
+
|
65
|
+
struct _amq_field_list_cls {
|
66
|
+
asl_field_list_t *field_list;
|
67
|
+
};
|
68
|
+
|
69
|
+
typedef struct _amq_field_list_cls amq_field_list_cls;
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
struct _amq_wire_api_cls {
|
74
|
+
int instance_id;
|
75
|
+
};
|
76
|
+
|
77
|
+
typedef struct _amq_wire_api_cls amq_wire_api_cls;
|
78
|
+
|
79
|
+
|
80
|
+
/* session allocator, destructor , accessor */
|
81
|
+
amq_session_cls* get_amq_session_cls(VALUE rb_obj,int raise);
|
82
|
+
void free_amq_session_cls( amq_session_cls *obj);
|
83
|
+
VALUE create_amq_session_cls(amq_client_session_t *session);
|
84
|
+
|
85
|
+
|
86
|
+
/* content allocator, destructor , accessor */
|
87
|
+
amq_content_cls* get_amq_content_cls(VALUE rb_obj,int raise);
|
88
|
+
void free_amq_content_cls( amq_content_cls *obj);
|
89
|
+
VALUE create_amq_content_cls(amq_content_basic_t *content);
|
90
|
+
|
91
|
+
|
92
|
+
/* connection allocator, destructor , accessor */
|
93
|
+
amq_connection_cls* get_amq_connection_cls(VALUE rb_obj,int raise);
|
94
|
+
void free_amq_connection_cls( amq_connection_cls *obj);
|
95
|
+
VALUE create_amq_connection_cls(amq_client_connection_t *connection);
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
/* connection allocator, destructor , accessor */
|
100
|
+
amq_auth_cls* get_amq_auth_cls(VALUE rb_obj,VALUE raise);
|
101
|
+
void free_amq_auth_cls( amq_auth_cls *obj) ;
|
102
|
+
VALUE create_amq_auth_cls(icl_longstr_t *auth);
|
103
|
+
|
104
|
+
|
105
|
+
/* int64_t allocator, destructor , accessor */
|
106
|
+
amq_int64_cls* get_amq_int64_cls(VALUE rb_obj) ;
|
107
|
+
void free_amq_int64_cls( amq_int64_cls *obj) ;
|
108
|
+
VALUE create_amq_int64_cls(int64_t int64);
|
109
|
+
|
110
|
+
|
111
|
+
/* field_list allocator, destructor , accessor */
|
112
|
+
amq_field_list_cls* get_amq_field_list_cls(VALUE rb_obj,VALUE raise);
|
113
|
+
void free_amq_field_list_cls( amq_field_list_cls *obj) ;
|
114
|
+
VALUE create_amq_field_list_cls(asl_field_list_t *field_list);
|
115
|
+
|
116
|
+
|
117
|
+
/* wire_api allocator, destructor , accessor */
|
118
|
+
amq_wire_api_cls* get_amq_wire_api_cls(VALUE rb_obj,VALUE raise);
|
119
|
+
void free_amq_wire_api_cls( amq_wire_api_cls *obj) ;
|
120
|
+
VALUE create_amq_wire_api_cls();
|
121
|
+
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
int VALUE2bool (VALUE v,const char *msg);
|
126
|
+
|
127
|
+
|
128
|
+
#endif
|
data/amq_wireapi.c
ADDED
@@ -0,0 +1,195 @@
|
|
1
|
+
/*===========================================================================
|
2
|
+
*
|
3
|
+
* OpenAMQ Ruby module
|
4
|
+
*
|
5
|
+
* Copyright (c) 2008 Benjamin April
|
6
|
+
*
|
7
|
+
* Permission is hereby granted, free of charge, to any person
|
8
|
+
* obtaining a copy of this software and associated documentation
|
9
|
+
* files (the "Software"), to deal in the Software without
|
10
|
+
* restriction, including without limitation the rights to use,
|
11
|
+
* copy, modify, merge, publish, distribute, sublicense, and/or sell
|
12
|
+
* copies of the Software, and to permit persons to whom the
|
13
|
+
* Software is furnished to do so, subject to the following
|
14
|
+
* conditions:
|
15
|
+
*
|
16
|
+
* The above copyright notice and this permission notice shall be
|
17
|
+
* included in all copies or substantial portions of the Software.
|
18
|
+
*
|
19
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
20
|
+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
21
|
+
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
22
|
+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
23
|
+
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
24
|
+
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
25
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
26
|
+
* OTHER DEALINGS IN THE SOFTWARE.
|
27
|
+
*
|
28
|
+
*===========================================================================*/
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
#include "ruby.h"
|
33
|
+
#include "asl.h"
|
34
|
+
#include "amq_client_connection.h"
|
35
|
+
#include "amq_client_session.h"
|
36
|
+
#include "amq_client_agent.h"
|
37
|
+
#include "amq_exchange.h"
|
38
|
+
#include "version.h"
|
39
|
+
#include <dlfcn.h>
|
40
|
+
#include <unistd.h>
|
41
|
+
|
42
|
+
VALUE rb_amq_error;
|
43
|
+
VALUE rb_amq_server_error;
|
44
|
+
|
45
|
+
|
46
|
+
// The order of these includes matters.
|
47
|
+
#include "amq_types.h"
|
48
|
+
#include "amq_content.h"
|
49
|
+
#include "amq_session.h"
|
50
|
+
#include "amq_connection.h"
|
51
|
+
#include "amq_field_list.h"
|
52
|
+
|
53
|
+
VALUE rb_wireapi;
|
54
|
+
VALUE amqp_auth;
|
55
|
+
|
56
|
+
|
57
|
+
static VALUE rbWireAPI_new(int argc, VALUE *argv,VALUE class) {
|
58
|
+
|
59
|
+
VALUE self=create_amq_wire_api_cls();
|
60
|
+
rb_obj_call_init(self, argc, argv);
|
61
|
+
|
62
|
+
return self;
|
63
|
+
}
|
64
|
+
|
65
|
+
|
66
|
+
static VALUE rbWireAPI_init(int argc, VALUE *argv,VALUE self)
|
67
|
+
|
68
|
+
{
|
69
|
+
VALUE trace;
|
70
|
+
rb_scan_args(argc,argv,"01",&trace);
|
71
|
+
|
72
|
+
int opt_trace = 0;
|
73
|
+
if FIXNUM_P(trace) {
|
74
|
+
opt_trace=FIX2INT(trace) ;
|
75
|
+
}
|
76
|
+
|
77
|
+
if (opt_trace) {
|
78
|
+
amq_client_connection_animate(opt_trace&4);
|
79
|
+
amq_client_session_animate (opt_trace&8);
|
80
|
+
}
|
81
|
+
return (self);
|
82
|
+
}
|
83
|
+
|
84
|
+
|
85
|
+
static VALUE rbWireAPI_debug_connection(VALUE self, VALUE val)
|
86
|
+
{
|
87
|
+
int connection_debug=VALUE2bool(val,"flag must be boolean");
|
88
|
+
amq_client_connection_animate (connection_debug);
|
89
|
+
return (self);
|
90
|
+
}
|
91
|
+
|
92
|
+
|
93
|
+
static VALUE rbWireAPI_debug_session(VALUE self, VALUE val)
|
94
|
+
{
|
95
|
+
int session_debug=VALUE2bool(val,"flag must be boolean");
|
96
|
+
amq_client_session_animate (session_debug);
|
97
|
+
return (self);
|
98
|
+
}
|
99
|
+
|
100
|
+
|
101
|
+
|
102
|
+
static VALUE rbWireAPI_client_connection_auth_plain (VALUE self, VALUE username, VALUE password)
|
103
|
+
{
|
104
|
+
icl_longstr_t *auth_data;
|
105
|
+
VALUE rb_auth_data;
|
106
|
+
char *_username;
|
107
|
+
char *_password;
|
108
|
+
if (TYPE(username) == T_STRING)
|
109
|
+
_username = StringValuePtr(username);
|
110
|
+
|
111
|
+
else
|
112
|
+
{
|
113
|
+
rb_raise(rb_eTypeError,"Username was not a string");
|
114
|
+
return Qnil;
|
115
|
+
}
|
116
|
+
if (TYPE(password) == T_STRING)
|
117
|
+
_password = StringValuePtr(password);
|
118
|
+
|
119
|
+
else
|
120
|
+
{
|
121
|
+
rb_raise(rb_eTypeError,"Password was not a string");
|
122
|
+
return Qnil;
|
123
|
+
}
|
124
|
+
auth_data = amq_client_connection_auth_plain (_username, _password);
|
125
|
+
rb_auth_data = create_amq_auth_cls(auth_data);
|
126
|
+
return(rb_auth_data);
|
127
|
+
}
|
128
|
+
|
129
|
+
static VALUE rbWireAPI_client_connection_new(VALUE self,
|
130
|
+
VALUE host,
|
131
|
+
VALUE vhost,
|
132
|
+
VALUE rb_auth_data,
|
133
|
+
VALUE client_name,
|
134
|
+
VALUE trace,
|
135
|
+
VALUE timeout)
|
136
|
+
{
|
137
|
+
icl_longstr_t *auth_data;
|
138
|
+
amq_client_connection_t *connection = NULL;
|
139
|
+
VALUE rb_connection;
|
140
|
+
char *_hostname = StringValuePtr(host);
|
141
|
+
char *_vhost = "/";
|
142
|
+
amq_auth_cls *auth_obj= get_amq_auth_cls(rb_auth_data,1);
|
143
|
+
if (TYPE(vhost)==T_STRING) {
|
144
|
+
_vhost = StringValuePtr(vhost);
|
145
|
+
}
|
146
|
+
char *_client_name = StringValuePtr(client_name);
|
147
|
+
int _trace=NUM2INT(trace) & 3; // trace (0-3)
|
148
|
+
int _timeout=NUM2INT(timeout);
|
149
|
+
|
150
|
+
// Open all connections
|
151
|
+
Data_Get_Struct(rb_auth_data,icl_longstr_t,auth_data);
|
152
|
+
connection = amq_client_connection_new (_hostname, _vhost,
|
153
|
+
auth_obj->auth,
|
154
|
+
_client_name,
|
155
|
+
_trace,
|
156
|
+
_timeout);
|
157
|
+
if (!connection)
|
158
|
+
rb_raise(rb_amq_error,"Could not connect to server");
|
159
|
+
|
160
|
+
rb_connection = create_amq_connection_cls(connection);
|
161
|
+
return (rb_connection);
|
162
|
+
}
|
163
|
+
|
164
|
+
|
165
|
+
void Init_WireAPI()
|
166
|
+
{
|
167
|
+
rb_wireapi = rb_define_class("WireAPI",rb_cObject);
|
168
|
+
amqp_auth = rb_define_class_under(rb_wireapi,"AMQ_Auth",rb_cObject);
|
169
|
+
rb_amq_error= rb_define_class_under(rb_wireapi,"AMQ_Error",rb_eRuntimeError);
|
170
|
+
rb_amq_server_error= rb_define_class_under(rb_wireapi,"AMQ_ServerError",rb_amq_error);
|
171
|
+
|
172
|
+
// WireAPI
|
173
|
+
rb_define_singleton_method(rb_wireapi, "new" ,
|
174
|
+
rbWireAPI_new , -1);
|
175
|
+
|
176
|
+
rb_define_method(rb_wireapi,"initialize",
|
177
|
+
rbWireAPI_init,-1);
|
178
|
+
|
179
|
+
rb_define_method(rb_wireapi,"auth_plain",
|
180
|
+
rbWireAPI_client_connection_auth_plain,2);
|
181
|
+
|
182
|
+
rb_define_method(rb_wireapi,"connection_new",
|
183
|
+
rbWireAPI_client_connection_new,6);
|
184
|
+
|
185
|
+
rb_define_method(rb_wireapi,"debug_connection=",
|
186
|
+
rbWireAPI_debug_connection,1);
|
187
|
+
|
188
|
+
rb_define_method(rb_wireapi,"debug_session=",
|
189
|
+
rbWireAPI_debug_session,1);
|
190
|
+
|
191
|
+
init_content();
|
192
|
+
init_connection();
|
193
|
+
init_session();
|
194
|
+
init_field_list();
|
195
|
+
}
|
data/extconf.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'mkmf'
|
2
|
+
|
3
|
+
$INCFLAGS += ' -I${AMQ_HOME}/include'
|
4
|
+
$LIBS += ' -L${AMQ_HOME}/lib -Wl,-rpath=${AMQ_HOME}/lib -lamq_wireapi -lamq_common -lsmt -licl -lipr -lasl -lapr -laprutil -lpcre'
|
5
|
+
|
6
|
+
|
7
|
+
unless ENV.include?('AMQ_HOME')
|
8
|
+
raise "Missing environment variable AMQ_HOME"
|
9
|
+
end
|
10
|
+
|
11
|
+
unless find_library("amq_wireapi", "amq_client_connection_auth_plain", "#{ENV['AMQ_HOME']}/lib")
|
12
|
+
raise "missing libamq_wireapi"
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
[
|
17
|
+
"amq_client_agent.h" ,
|
18
|
+
"amq_client_connection.h" ,
|
19
|
+
"amq_client_session.h" ,
|
20
|
+
"asl.h" ,
|
21
|
+
"icl.h" ,
|
22
|
+
"wireapi.h" ,
|
23
|
+
].each do |header_file|
|
24
|
+
unless find_header(header_file, "#{ENV['AMQ_HOME']}/include")
|
25
|
+
raise "missing #{header_file}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
create_makefile("WireAPI")
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: WireAPI
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: "0.3"
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jurgen Van Ham
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-04 00:00:00 +02:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: jvh@vasco.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions:
|
21
|
+
- ./extconf.rb
|
22
|
+
extra_rdoc_files: []
|
23
|
+
|
24
|
+
files:
|
25
|
+
- ./amq_field_list.c
|
26
|
+
- ./amq_types.c
|
27
|
+
- ./amq_session.c
|
28
|
+
- ./amq_content.c
|
29
|
+
- ./amq_wireapi.c
|
30
|
+
- ./amq_connection.c
|
31
|
+
- ./extconf.rb
|
32
|
+
- ./amq_field_list.h
|
33
|
+
- ./amq_types.h
|
34
|
+
- ./amq_session.h
|
35
|
+
- ./amq_content.h
|
36
|
+
- ./amq_connection.h
|
37
|
+
has_rdoc: false
|
38
|
+
homepage: http://svn.able.be/svn/ruby_OpenAMQ
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
|
42
|
+
require_paths:
|
43
|
+
- .
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
version:
|
56
|
+
requirements: []
|
57
|
+
|
58
|
+
rubyforge_project:
|
59
|
+
rubygems_version: 1.3.1
|
60
|
+
signing_key:
|
61
|
+
specification_version: 2
|
62
|
+
summary: Ruby binding to OpenAMQ WireAPI
|
63
|
+
test_files: []
|
64
|
+
|