@@ -46,59 +46,22 @@ void convert_acl_to_array(Array *destArray, struct ACL_vector *acl) {
4646 }
4747}
4848
49- // // 把一个数组转化为acl结构体,由于接口对外需要严格检查数据结构
50- bool convert_array_to_acl (Array *param_array, struct ACL_vector *zookeeper_acl) {
51- Variant tmp_unit_check;
52- // 初始化结构体
53- zookeeper_acl->count = (int32_t ) param_array->count ();
54-
55- struct ACL zookeeper_acl_unit[zookeeper_acl->count ];
56-
57- for (int i = 0 ; i < zookeeper_acl->count ; i++) {
58- struct Id acl_unit;
59- tmp_unit_check = param_array->get (i);
60- // 检查索引防止用户填写错误
61- if (tmp_unit_check == nullptr ) {
62- error (E_WARNING, " setAcl:get index error" );
63- return false ;
64- }
65- Array acl_unit_array (tmp_unit_check);
66-
67- // 检查索引防止用户填写错误
68- if (tmp_unit_check == nullptr ) {
69- error (E_WARNING, " setAcl:get id error" );
70- return false ;
71- }
72-
73- tmp_unit_check = acl_unit_array.get (" id" );
74- Array acl_unit_array_id (tmp_unit_check);
75- zookeeper_acl_unit[i].perms = (int32_t ) acl_unit_array.get (" perms" ).toInt ();
76- auto id = acl_unit_array_id.get (" id" ).toStdString ();
77- acl_unit.id = estrndup (id.c_str (), id.length ());
78- auto scheme = acl_unit_array_id.get (" scheme" ).toStdString ();
79- acl_unit.scheme = estrndup (scheme.c_str (), scheme.length ());
80- zookeeper_acl_unit[i].id = acl_unit;
81- }
82- zookeeper_acl->data = zookeeper_acl_unit;
83- return zookeeper_acl;
84- }
85-
86- // 把一个数组转化为acl结构体
49+ // 把一个数组转化为acl结构体
8750struct ACL_vector *convert_array_to_acl (Array *param_array) {
8851 struct ACL_vector *acl_vector;
8952 struct ACL *create_acl;
9053 struct ACL *acl_collect;
91- // 初始化结构体
54+ // 初始化结构体
9255 Array zk_array (*param_array);
9356 acl_vector = (struct ACL_vector *) emalloc (sizeof (struct ACL_vector ));
9457
95- // 初始化这个结构体
58+ // 初始化这个结构体
9659 bzero (acl_vector, sizeof (struct ACL_vector ));
9760
98- // 设置这个架构体里acl的数量
61+ // 设置这个架构体里acl的数量
9962 acl_vector->count = (int32_t ) zk_array.count ();
10063
101- // 申请一块连续的内存空间
64+ // 申请一块连续的内存空间
10265 acl_collect = (struct ACL *) emalloc (acl_vector->count * sizeof (struct ACL ));
10366 if (acl_collect == nullptr ) {
10467 return nullptr ;
@@ -146,7 +109,7 @@ struct ACL_vector *convert_array_to_acl(Array *param_array) {
146109 std::string std_acl_struct_id = acl_struct_id.toStdString ();
147110 create_acl.id .id = estrndup (std_acl_struct_id.c_str (), std_acl_struct_id.length ());
148111
149- // 将结构体装入ACL
112+ // 将结构体装入ACL
150113 acl_collect[i] = create_acl;
151114 }
152115 acl_vector->data = acl_collect;
@@ -157,9 +120,9 @@ struct ACL_vector *convert_array_to_acl(Array *param_array) {
157120bool free_acl_struct (struct ACL_vector *acl_vector) {
158121 if (acl_vector && acl_vector->data ) {
159122 for (int i = 0 ; i < acl_vector->count ; i++) {
160- efree ( const_cast < char *>(( acl_vector->data + i)-> id .id )) ;
161- efree (const_cast < char *>((acl_vector-> data + i)-> id .scheme ) );
162- efree ((acl_vector-> data + i) );
123+ Id id = acl_vector->data [i] .id ;
124+ efree (id.id );
125+ efree (id. scheme );
163126 }
164127 efree (acl_vector->data );
165128 efree (acl_vector);
0 commit comments