Skip to content

Commit ab7e2a5

Browse files
committed
add KModelPtr so named_mark/named_acl can set revers/or
1 parent 35f3de7 commit ab7e2a5

File tree

10 files changed

+178
-128
lines changed

10 files changed

+178
-128
lines changed

console/src/views/acccess/ChainView.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,24 +217,24 @@ onMounted(() => {
217217
</tr>
218218
<template v-for="(modules, type) in [chain_value.acl, chain_value.mark]">
219219
<tr v-for="(m, index) in modules">
220+
<input type="hidden" name="begin_sub_form" :value="(type == 0 ? 'acl_' : 'mark_') + m.module" />
220221
<td>
221222
[<a href=# @click="delModule(type, index)">删</a>]
222223
[<a href=# @click="UpModule(type, index)">UP</a>]
223224
<span v-if="m.module">
224225
{{ m.module }}
225226
</span>
227+
<input type=checkbox name='revers' value='1' :checked="m.revers>0">NOT
228+
<input type=checkbox name='or' value='1' :checked="m.is_or>0">OR
226229
</td>
227-
<td>
228-
229-
<input type="hidden" name="begin_sub_form" :value="(type == 0 ? 'acl_' : 'mark_') + m.module" />
230+
<td>
230231
<template v-if="m.ref">
231232
<input type="hidden" name="ref" :value="m.ref" />命名模块:{{ m.ref }}
232233
</template>
233234
<template v-else>
234235
<ModuleView :module="m" />
235236
</template>
236237
<input type="hidden" name="end_sub_form" value='1' />
237-
238238
</td>
239239
</tr>
240240
<tr>

console/src/views/acccess/TableView.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,14 @@ onMounted(flushChain);
111111
<td>{{ chain.action }}<span v-if="chain.jump">:{{ chain.jump }}</span></td>
112112
<td>
113113
<div v-for="m in chain.v.acl">
114-
{{ m.module }} {{ m.ref }} <span v-if="m.revers">!</span><span v-html="m.html"></span>
114+
<span v-if="m.revers">!</span>{{ m.module }} {{ m.ref }} <span v-html="m.html"></span>
115+
<span v-if="m.is_or>0"> ||</span>
115116
</div>
116117
</td>
117118
<td>
118119
<div v-for="m in chain.v.mark">
119-
{{ m.module }} {{ m.ref }}<span v-html="m.html"></span>
120+
<span v-if="m.revers">!</span>{{ m.module }} {{ m.ref }}<span v-html="m.html"></span>
121+
<span v-if="m.is_or>0"> ||</span>
120122
</div>
121123
</td>
122124
<td>{{ chain.v.hit }}</td>

include/KAccess.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ class KVirtualHostEvent;
4747
class WhmContext;
4848
using KSafeTable = KSharedObj<KTable>;
4949
void bind_access_config(kconfig::KConfigTree* tree, KAccess* access);
50-
void parse_module_config(KModel* m, const khttpd::KXmlNodeBody* xml);
5150
class KAccess final : public kconfig::KConfigListen
5251
{
5352
public:
@@ -65,28 +64,30 @@ class KAccess final : public kconfig::KConfigListen
6564
kconfig::KConfigEventFlag config_flag() const override {
6665
return kconfig::ev_self | kconfig::ev_subdir;
6766
}
68-
KSafeAcl new_acl(const KString& name, const khttpd::KXmlNodeBody* xml) {
67+
KModelPtr<KAcl> new_acl(const KString& name, const khttpd::KXmlNodeBody* xml) {
6968
auto it = KAccess::acl_factorys[type].find(name);
7069
if (it == KAccess::acl_factorys[type].end()) {
7170
return nullptr;
7271
}
73-
KSafeAcl m((*it).second->new_instance());
74-
if (m) {
75-
m->isGlobal = isGlobal();
72+
KModelPtr<KAcl> m((*it).second->new_instance());
73+
if (m.m) {
74+
m.m->isGlobal = isGlobal();
7675
}
77-
parse_module_config(m.get(), xml);
76+
m.parse_config(xml);
77+
m.m->parse_config(xml);
7878
return m;
7979
}
80-
KSafeMark new_mark(const KString& name, const khttpd::KXmlNodeBody* xml) {
80+
KModelPtr<KMark> new_mark(const KString& name, const khttpd::KXmlNodeBody* xml) {
8181
auto it = KAccess::mark_factorys[type].find(name);
8282
if (it == KAccess::mark_factorys[type].end()) {
8383
return nullptr;
8484
}
85-
KSafeMark m((*it).second->new_instance());
86-
if (m) {
87-
m->isGlobal = isGlobal();
85+
KModelPtr<KMark> m((*it).second->new_instance());
86+
if (m.m) {
87+
m.m->isGlobal = isGlobal();
8888
}
89-
parse_module_config(m.get(), xml);
89+
m.parse_config(xml);
90+
m.m->parse_config(xml);
9091
return m;
9192
}
9293
kgl_ref_str_t get_qname() {
@@ -140,8 +141,8 @@ class KAccess final : public kconfig::KConfigListen
140141
void inter_destroy();
141142
void htmlChainAction(KWStream& s, kgl_jump_type jump_type, KJump* jump, bool showTable, const KString& skipTable);
142143
void htmlRadioAction(KWStream& s, kgl_jump_type* jump_value, int jump_type, KJump* jump, int my_jump_type, const KString& my_type_name, std::vector<KString>& table_names);
143-
KSafeAcl get_named_acl(const KString& name);
144-
KSafeMark get_named_mark(const KString& name);
144+
KModelPtr<KAcl> get_named_acl(const KString& name);
145+
KModelPtr<KMark> get_named_mark(const KString& name);
145146
KFiberReadLocker read_lock() {
146147
return KFiberReadLocker(rwlock);
147148
}

include/KChain.h

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
#include <vector>
2828
#include "kmalloc.h"
2929
#include "KUrlValue.h"
30-
30+
#include "KModelPtr.h"
3131
#define CHAIN_CONTEXT "chain"
3232
class KAccess;
3333

@@ -42,11 +42,11 @@ class KChain final
4242
//OR NEXT
4343
for (auto it = acls.begin(); it != acls.end(); ++it) {
4444
if (result && last_or) {
45-
last_or = (*it)->is_or;
45+
last_or = (*it).is_or;
4646
continue;
4747
}
48-
result = ((*it)->match(rq, obj) != (*it)->revers) ? KF_STATUS_REQ_TRUE : KF_STATUS_REQ_FALSE;
49-
last_or = (*it)->is_or;
48+
result = ((*it).m->match(rq, obj) != (*it).revers) ? KF_STATUS_REQ_TRUE : KF_STATUS_REQ_FALSE;
49+
last_or = (*it).is_or;
5050
if (!result && !last_or) {
5151
break;
5252
}
@@ -57,15 +57,15 @@ class KChain final
5757
last_or = false;
5858
for (auto it = marks.begin(); it != marks.end(); ++it) {
5959
if (result && last_or) {
60-
last_or = (*it)->is_or;
60+
last_or = (*it).is_or;
6161
continue;
6262
}
63-
result = (*it)->process(rq, obj, fo);
63+
result = (*it).m->process(rq, obj, fo);
6464
if (KBIT_TEST(result, KF_STATUS_REQ_FINISHED)) {
6565
++hit_count;
6666
return result;
6767
}
68-
result = (!!result != (*it)->revers) ? KF_STATUS_REQ_TRUE : KF_STATUS_REQ_FALSE;
68+
result = (!!result != (*it).revers) ? KF_STATUS_REQ_TRUE : KF_STATUS_REQ_FALSE;
6969
if (!result && !last_or) {
7070
break;
7171
}
@@ -91,13 +91,41 @@ class KChain final
9191
private:
9292
void get_edit_html(kgl::serializable* s);
9393
void get_edit_html(KWStream& s, u_short accessType);
94-
void getModelHtml(KModel* model, KWStream& s, int type, int index);
94+
template<typename T>
95+
void getModelHtml(KModelPtr<T> &ptr, KWStream& s, int type, int index) {
96+
s << "<tr><td><input type=hidden name='begin_sub_form' value='"
97+
<< (type == 0 ? "acl_"_CS : "mark_"_CS)
98+
<< ptr.m->getName() << "'>";
99+
s << "[<a href=\"javascript:delmodel('" << index << "'," << type << ");\">del</a>]";
100+
if (ptr.named.empty()) {
101+
s << "<input type = checkbox name = 'or' value = '1' ";
102+
if (ptr.is_or) {
103+
s << "checked";
104+
}
105+
s << ">OR";
106+
s << "<input type=checkbox name='revers' value='1' ";
107+
if (ptr.revers) {
108+
s << "checked";
109+
}
110+
s << ">NOT ";
111+
s << ptr.m->getName();
112+
} else {
113+
s << "named:" << ptr.named;
114+
}
115+
s << "</td><td>";
116+
if (ptr.named.empty()) {
117+
ptr.m->get_html(s);
118+
} else {
119+
s << "<input type='hidden' name='ref' value='" << ptr.named << "'/>";
120+
s << "named model do not support";
121+
}
122+
s << "<input type=hidden name='end_sub_form' value='1'></td></tr>\n";
123+
}
95124
private:
96-
97125
uint32_t hit_count;
98126
kgl_jump_type jump_type;
99127
KSafeJump jump;
100-
std::vector<KAcl*> acls;
101-
std::vector<KMark*> marks;
128+
std::vector<KModelPtr<KAcl>> acls;
129+
std::vector<KModelPtr<KMark>> marks;
102130
};
103131
#endif /*KCHAIN_H_*/

include/KModel.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ using KSafeSource = std::unique_ptr<KFetchObject>;
3535
class KModel {
3636
public:
3737
KModel() {
38-
revers = false;
39-
is_or = false;
38+
//revers = false;
39+
//is_or = false;
4040
isGlobal = true;
4141
ref = 1;
4242
}
@@ -60,12 +60,9 @@ class KModel {
6060
}
6161
}
6262
void dump(kgl::serializable* m, bool is_short) {
63-
m->add("revers", revers);
64-
m->add("is_or", is_or);
63+
//m->add("revers", revers);
64+
//m->add("is_or", is_or);
6565
m->add("module", getName());
66-
if (!named.empty()) {
67-
m->add("ref", named);
68-
}
6966
KStringBuf out;
7067
if (is_short) {
7168
get_display(out);
@@ -75,10 +72,10 @@ class KModel {
7572
m->add("html", out.str());
7673
}
7774
/* 命名模块的名字 */
78-
KString named;
79-
bool revers;
80-
bool is_or;
81-
bool isGlobal;
75+
//KString named;
76+
//bool revers;
77+
//bool is_or;
78+
bool isGlobal;
8279
protected:
8380
volatile uint32_t ref;
8481
virtual ~KModel() {

include/KModelPtr.h

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#ifndef KMODELPTR_H_INCLUDED
2+
#define KMODELPTR_H_INCLUDED
3+
#include "serializable.h"
4+
template<typename T>
5+
class KModelPtr {
6+
public:
7+
KModelPtr(T* m) {
8+
revers = false;
9+
is_or = false;
10+
this->m = m;
11+
}
12+
KModelPtr(const KString& named, T* m) : named{ named } {
13+
revers = false;
14+
is_or = false;
15+
if (!m) {
16+
throw std::bad_exception();
17+
}
18+
this->m = m;
19+
}
20+
KModelPtr(const KModelPtr& ptr) :named{ ptr.named } {
21+
if (ptr.m) {
22+
this->m = static_cast<T*>(ptr.m->add_ref());
23+
} else {
24+
this->m = nullptr;
25+
}
26+
this->revers = ptr.revers;
27+
this->is_or = ptr.is_or;
28+
}
29+
~KModelPtr() {
30+
if (m) {
31+
m->release();
32+
}
33+
}
34+
explicit operator bool() const noexcept {
35+
return m != nullptr;
36+
}
37+
KModelPtr& operator =(const KModelPtr& ptr) {
38+
if (this == *ptr) {
39+
return *this;
40+
}
41+
if (m) {
42+
m->release();
43+
m = nullptr;
44+
}
45+
if (ptr.m) {
46+
this->m = static_cast<T*>(ptr.m->add_ref());
47+
}
48+
this->revers = ptr.revers;
49+
this->is_or = ptr.is_or;
50+
this->named = ptr.named;
51+
return *this;
52+
}
53+
void parse_config(const khttpd::KXmlNodeBody* xml) {
54+
revers = (xml->attributes["revers"] == "1");
55+
is_or = (xml->attributes["or"] == "1");
56+
//m->parse_config(xml);
57+
}
58+
void dump(kgl::serializable* m, bool is_short) {
59+
m->add("revers", revers);
60+
m->add("is_or", is_or);
61+
if (!named.empty()) {
62+
m->add("ref", named);
63+
}
64+
if (this->m) {
65+
this->m->dump(m, is_short);
66+
}
67+
}
68+
bool revers;
69+
bool is_or;
70+
/* ÃüÃûÄ£¿éµÄÃû×Ö */
71+
KString named;
72+
T* m;
73+
};
74+
#endif // !KMODELPTR_H_INCLUDED

include/KNamedModel.h

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,16 @@
33
#include "KConfigTree.h"
44
#include "KModel.h"
55
#include "KSharedObj.h"
6+
#include "KModelPtr.h"
67

7-
class KNamedMark final: public KMark {
8-
public:
9-
KMark* new_instance() {
10-
return static_cast<KMark *>(add_ref());
11-
}
12-
virtual const char* getName() override {
13-
return mark->getName();
14-
}
15-
virtual void parse_config(const khttpd::KXmlNodeBody* xml) override {
16-
17-
}
18-
virtual void parse_child(const kconfig::KXmlChanged* changed)override {
19-
}
20-
virtual void get_display(KWStream& s)override {
21-
}
22-
virtual void get_html(KWStream& s) override {
23-
}
24-
/* return KF_STATUS_REQ_FALSE, KF_STATUS_REQ_TRUE,KF_STATUS_REQ_FINISHED */
25-
uint32_t process(KHttpRequest* rq, KHttpObject* obj, KSafeSource& fo) override {
26-
return mark->process(rq, obj, fo);
27-
}
28-
private:
29-
KSafeMark mark;
30-
};
318
class KNamedModel : public kconfig::KConfigListen
329
{
3310
public:
3411
KNamedModel(KString name, const KSafeModel& model) : name{ name },m(model) {
3512
ref = 1;
36-
m->named = name;
13+
}
14+
KNamedModel(KString name, KModel *model) : name{ name }, m(model->add_ref()) {
15+
ref = 1;
3716
}
3817
KNamedModel* add_ref() {
3918
katom_inc((void*)&ref);
@@ -47,11 +26,11 @@ class KNamedModel : public kconfig::KConfigListen
4726
KModel *get_module() {
4827
return m.get();
4928
}
50-
KSafeAcl as_acl() {
51-
return KSafeAcl(static_cast<KAcl *>(m->add_ref()));
29+
KModelPtr<KAcl> as_acl() {
30+
return KModelPtr<KAcl>(name, static_cast<KAcl *>(m.get()->add_ref()));
5231
}
53-
KSafeMark as_mark() {
54-
return KSafeMark(static_cast<KMark*>(m->add_ref()));
32+
KModelPtr<KMark> as_mark() {
33+
return KModelPtr<KMark>(name, static_cast<KMark*>(m.get()->add_ref()));
5534
}
5635
kconfig::KConfigEventFlag config_flag() const {
5736
return kconfig::ev_subdir;

0 commit comments

Comments
 (0)