@@ -44,182 +44,6 @@ static PyObject *AerospikeClient_InfoAll_Invoke(AerospikeClient *self,
44
44
PyObject * py_policy );
45
45
46
46
static PyObject * get_formatted_info_response (const char * response );
47
- /**
48
- ********************************************************************************************************
49
- * Macros for Info API.
50
- ********************************************************************************************************
51
- */
52
- #define INET_ADDRSTRLEN 16
53
- #define INET6_ADDRSTRLEN 46
54
- #define INET_PORT 5
55
- #define IP_PORT_SEPARATOR_LEN 1
56
- // Add 2 to the length to facilitate [] around the edges
57
- #define IP_PORT_MAX_LEN INET6_ADDRSTRLEN + INET_PORT + IP_PORT_SEPARATOR_LEN + 2
58
-
59
- /**
60
- *******************************************************************************************************
61
- * Callback for as_info_foreach().
62
- *
63
- * @param err The as_error to be populated by the function
64
- * with the encountered error if any.
65
- * @param node The current as_node object for which the
66
- * callback is fired by c client.
67
- * @param req The info request string.
68
- * @param res The info response string for current node.
69
- * @pram udata The callback udata containing the host_lookup
70
- * array and the return zval to be populated with
71
- * an entry for current node's info response with
72
- * the node's ID as the key.
73
- *
74
- * Returns true if callback is successful, Otherwise false.
75
- *******************************************************************************************************
76
- */
77
- static bool AerospikeClient_Info_each (as_error * err , const as_node * node ,
78
- const char * req , char * res , void * udata )
79
- {
80
- PyObject * py_err = NULL ;
81
- PyObject * py_ustr = NULL ;
82
- PyObject * py_out = NULL ;
83
- foreach_callback_info_udata * udata_ptr =
84
- (foreach_callback_info_udata * )udata ;
85
- as_address * addr = NULL ;
86
-
87
- // Need to make sure we have the GIL since we're back in python land now
88
- PyGILState_STATE gil_state = PyGILState_Ensure ();
89
-
90
- if (err && err -> code != AEROSPIKE_OK ) {
91
- as_error_update (err , err -> code , NULL );
92
- goto CLEANUP ;
93
- }
94
- else if (res ) {
95
- char * out = strchr (res , '\t' );
96
- if (out ) {
97
- out ++ ;
98
- py_out = PyUnicode_FromString (out );
99
- }
100
- else {
101
- py_out = PyUnicode_FromString (res );
102
- }
103
- }
104
-
105
- if (!py_err ) {
106
- Py_INCREF (Py_None );
107
- py_err = Py_None ;
108
- }
109
-
110
- if (!py_out ) {
111
- Py_INCREF (Py_None );
112
- py_out = Py_None ;
113
- }
114
-
115
- PyObject * py_res = PyTuple_New (2 );
116
- PyTuple_SetItem (py_res , 0 , py_err );
117
- PyTuple_SetItem (py_res , 1 , py_out );
118
-
119
- if (udata_ptr -> host_lookup_p ) {
120
- PyObject * py_hosts = (PyObject * )udata_ptr -> host_lookup_p ;
121
- if (py_hosts && PyList_Check (py_hosts )) {
122
- addr = as_node_get_address ((as_node * )node );
123
- int size = (int )PyList_Size (py_hosts );
124
- for (int i = 0 ; i < size ; i ++ ) {
125
- char * host_addr = NULL ;
126
- int port = -1 ;
127
- PyObject * py_host = PyList_GetItem (py_hosts , i );
128
- if (PyTuple_Check (py_host ) && PyTuple_Size (py_host ) == 2 ) {
129
- PyObject * py_addr = PyTuple_GetItem (py_host , 0 );
130
- PyObject * py_port = PyTuple_GetItem (py_host , 1 );
131
- if (PyUnicode_Check (py_addr )) {
132
- py_ustr = PyUnicode_AsUTF8String (py_addr );
133
- host_addr = PyBytes_AsString (py_ustr );
134
- }
135
- else {
136
- as_error_update (& udata_ptr -> error , AEROSPIKE_ERR_PARAM ,
137
- "Host address is of type incorrect" );
138
- if (py_res ) {
139
- Py_DECREF (py_res );
140
- }
141
- PyGILState_Release (gil_state );
142
- return false;
143
- }
144
- if (PyLong_Check (py_port )) {
145
- port = (uint16_t )PyLong_AsLong (py_port );
146
- }
147
- else {
148
- break ;
149
- }
150
- char ip_port [IP_PORT_MAX_LEN ];
151
- // If the address is longer than the max length of an ipv6 address, raise an error and exit
152
- if (strnlen (host_addr , INET6_ADDRSTRLEN ) >=
153
- INET6_ADDRSTRLEN ) {
154
- as_error_update (& udata_ptr -> error , AEROSPIKE_ERR_PARAM ,
155
- "Host address is too long" );
156
- if (py_res ) {
157
- Py_DECREF (py_res );
158
- }
159
- goto CLEANUP ;
160
- }
161
- sprintf (ip_port , "%s:%d" , host_addr , port );
162
- if (!strcmp (ip_port , addr -> name )) {
163
- PyObject * py_nodes = (PyObject * )udata_ptr -> udata_p ;
164
- PyDict_SetItemString (py_nodes , node -> name , py_res );
165
- }
166
- else {
167
- sprintf (ip_port , "[%s]:%d" , host_addr , port );
168
- if (!strcmp (ip_port , addr -> name )) {
169
- PyObject * py_nodes = (PyObject * )udata_ptr -> udata_p ;
170
- PyDict_SetItemString (py_nodes , node -> name , py_res );
171
- }
172
- }
173
- }
174
-
175
- if (py_ustr ) {
176
- Py_DECREF (py_ustr );
177
- py_ustr = NULL ;
178
- }
179
- }
180
- }
181
- else if (!PyList_Check (py_hosts )) {
182
- as_error_update (& udata_ptr -> error , AEROSPIKE_ERR_PARAM ,
183
- "Hosts should be specified in a list." );
184
- if (py_res ) {
185
- Py_DECREF (py_res );
186
- }
187
- goto CLEANUP ;
188
- }
189
- }
190
- else {
191
- PyObject * py_nodes = (PyObject * )udata_ptr -> udata_p ;
192
- PyDict_SetItemString (py_nodes , node -> name , py_res );
193
- }
194
-
195
- Py_DECREF (py_res );
196
-
197
- CLEANUP :
198
- if (py_ustr ) {
199
- Py_DECREF (py_ustr );
200
- }
201
- if (udata_ptr -> error .code != AEROSPIKE_OK ) {
202
- PyObject * py_err = NULL ;
203
- error_to_pyobject (& udata_ptr -> error , & py_err );
204
- PyObject * exception_type = raise_exception_old (& udata_ptr -> error );
205
- PyErr_SetObject (exception_type , py_err );
206
- Py_DECREF (py_err );
207
- PyGILState_Release (gil_state );
208
- return NULL ;
209
- }
210
- if (err -> code != AEROSPIKE_OK ) {
211
- PyObject * py_err = NULL ;
212
- error_to_pyobject (err , & py_err );
213
- PyObject * exception_type = raise_exception_old (err );
214
- PyErr_SetObject (exception_type , py_err );
215
- Py_DECREF (py_err );
216
- PyGILState_Release (gil_state );
217
- return NULL ;
218
- }
219
-
220
- PyGILState_Release (gil_state );
221
- return true;
222
- }
223
47
224
48
/**
225
49
*******************************************************************************************************
@@ -297,110 +121,6 @@ static bool AerospikeClient_InfoAll_each(as_error *err, const as_node *node,
297
121
return true;
298
122
}
299
123
300
- /**
301
- *******************************************************************************************************
302
- * Sends an info request to all the nodes in a cluster.
303
- *
304
- * @param self AerospikeClient object
305
- * @param args The args is a tuple object containing an argument
306
- * list passed from Python to a C function
307
- * @param kwds Dictionary of keywords
308
- *
309
- * Returns a server response for the particular request string.
310
- * In case of error,appropriate exceptions will be raised.
311
- *******************************************************************************************************
312
- */
313
- PyObject * AerospikeClient_Info (AerospikeClient * self , PyObject * args ,
314
- PyObject * kwds )
315
- {
316
- PyObject * py_req = NULL ;
317
- PyObject * py_policy = NULL ;
318
- PyObject * py_hosts = NULL ;
319
- PyObject * py_nodes = NULL ;
320
- PyObject * py_ustr = NULL ;
321
- foreach_callback_info_udata info_callback_udata ;
322
-
323
- static char * kwlist [] = {"command" , "hosts" , "policy" , NULL };
324
-
325
- if (PyArg_ParseTupleAndKeywords (args , kwds , "O|OO:info" , kwlist , & py_req ,
326
- & py_hosts , & py_policy ) == false) {
327
- return NULL ;
328
- }
329
-
330
- as_error err ;
331
- as_error_init (& err );
332
-
333
- as_policy_info info_policy ;
334
- as_policy_info * info_policy_p = NULL ;
335
- py_nodes = PyDict_New ();
336
- info_callback_udata .udata_p = py_nodes ;
337
- info_callback_udata .host_lookup_p = py_hosts ;
338
- as_error_init (& info_callback_udata .error );
339
-
340
- if (!self || !self -> as ) {
341
- as_error_update (& err , AEROSPIKE_ERR_PARAM , "Invalid aerospike object" );
342
- goto CLEANUP ;
343
- }
344
- if (!self -> is_conn_16 ) {
345
- as_error_update (& err , AEROSPIKE_ERR_CLUSTER ,
346
- "No connection to aerospike cluster" );
347
- goto CLEANUP ;
348
- }
349
-
350
- // Convert python policy object to as_policy_info
351
- pyobject_to_policy_info (& err , py_policy , & info_policy , & info_policy_p ,
352
- & self -> as -> config .policies .info );
353
- if (err .code != AEROSPIKE_OK ) {
354
- goto CLEANUP ;
355
- }
356
- char * req = NULL ;
357
- if (PyUnicode_Check (py_req )) {
358
- py_ustr = PyUnicode_AsUTF8String (py_req );
359
- req = PyBytes_AsString (py_ustr );
360
- }
361
- else {
362
- as_error_update (& err , AEROSPIKE_ERR_PARAM , "Request must be a string" );
363
- goto CLEANUP ;
364
- }
365
-
366
- Py_BEGIN_ALLOW_THREADS
367
- aerospike_info_foreach (
368
- self -> as , & err , info_policy_p , req ,
369
- (aerospike_info_foreach_callback )AerospikeClient_Info_each ,
370
- & info_callback_udata );
371
- Py_END_ALLOW_THREADS
372
-
373
- if (info_callback_udata .error .code != AEROSPIKE_OK ) {
374
- as_error_update (& err , err .code , NULL );
375
- goto CLEANUP ;
376
- }
377
- CLEANUP :
378
- if (py_ustr ) {
379
- Py_DECREF (py_ustr );
380
- }
381
- if (info_callback_udata .error .code != AEROSPIKE_OK ) {
382
- PyObject * py_err = NULL ;
383
- error_to_pyobject (& info_callback_udata .error , & py_err );
384
- PyObject * exception_type =
385
- raise_exception_old (& info_callback_udata .error );
386
- PyErr_SetObject (exception_type , py_err );
387
- Py_DECREF (py_err );
388
- if (py_nodes ) {
389
- Py_DECREF (py_nodes );
390
- }
391
- return NULL ;
392
- }
393
- if (err .code != AEROSPIKE_OK ) {
394
- raise_exception (& err );
395
- if (py_nodes ) {
396
- Py_DECREF (py_nodes );
397
- }
398
- return NULL ;
399
- }
400
-
401
- return info_callback_udata .udata_p ;
402
- }
403
-
404
124
/**
405
125
*******************************************************************************************************
406
126
* Sends an info request to all the nodes in a cluster.
0 commit comments