Skip to content

Commit

Permalink
add KModelPtr so named_mark/named_acl can set revers/or
Browse files Browse the repository at this point in the history
  • Loading branch information
keengo99 committed Jan 16, 2025
1 parent 35f3de7 commit ab7e2a5
Show file tree
Hide file tree
Showing 10 changed files with 178 additions and 128 deletions.
8 changes: 4 additions & 4 deletions console/src/views/acccess/ChainView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -217,24 +217,24 @@ onMounted(() => {
</tr>
<template v-for="(modules, type) in [chain_value.acl, chain_value.mark]">
<tr v-for="(m, index) in modules">
<input type="hidden" name="begin_sub_form" :value="(type == 0 ? 'acl_' : 'mark_') + m.module" />
<td>
[<a href=# @click="delModule(type, index)">删</a>]
[<a href=# @click="UpModule(type, index)">UP</a>]
<span v-if="m.module">
{{ m.module }}
</span>
<input type=checkbox name='revers' value='1' :checked="m.revers>0">NOT
<input type=checkbox name='or' value='1' :checked="m.is_or>0">OR
</td>
<td>

<input type="hidden" name="begin_sub_form" :value="(type == 0 ? 'acl_' : 'mark_') + m.module" />
<td>
<template v-if="m.ref">
<input type="hidden" name="ref" :value="m.ref" />命名模块:{{ m.ref }}
</template>
<template v-else>
<ModuleView :module="m" />
</template>
<input type="hidden" name="end_sub_form" value='1' />

</td>
</tr>
<tr>
Expand Down
6 changes: 4 additions & 2 deletions console/src/views/acccess/TableView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,14 @@ onMounted(flushChain);
<td>{{ chain.action }}<span v-if="chain.jump">:{{ chain.jump }}</span></td>
<td>
<div v-for="m in chain.v.acl">
{{ m.module }} {{ m.ref }} <span v-if="m.revers">!</span><span v-html="m.html"></span>
<span v-if="m.revers">!</span>{{ m.module }} {{ m.ref }} <span v-html="m.html"></span>
<span v-if="m.is_or>0"> ||</span>
</div>
</td>
<td>
<div v-for="m in chain.v.mark">
{{ m.module }} {{ m.ref }}<span v-html="m.html"></span>
<span v-if="m.revers">!</span>{{ m.module }} {{ m.ref }}<span v-html="m.html"></span>
<span v-if="m.is_or>0"> ||</span>
</div>
</td>
<td>{{ chain.v.hit }}</td>
Expand Down
27 changes: 14 additions & 13 deletions include/KAccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class KVirtualHostEvent;
class WhmContext;
using KSafeTable = KSharedObj<KTable>;
void bind_access_config(kconfig::KConfigTree* tree, KAccess* access);
void parse_module_config(KModel* m, const khttpd::KXmlNodeBody* xml);
class KAccess final : public kconfig::KConfigListen
{
public:
Expand All @@ -65,28 +64,30 @@ class KAccess final : public kconfig::KConfigListen
kconfig::KConfigEventFlag config_flag() const override {
return kconfig::ev_self | kconfig::ev_subdir;
}
KSafeAcl new_acl(const KString& name, const khttpd::KXmlNodeBody* xml) {
KModelPtr<KAcl> new_acl(const KString& name, const khttpd::KXmlNodeBody* xml) {
auto it = KAccess::acl_factorys[type].find(name);
if (it == KAccess::acl_factorys[type].end()) {
return nullptr;
}
KSafeAcl m((*it).second->new_instance());
if (m) {
m->isGlobal = isGlobal();
KModelPtr<KAcl> m((*it).second->new_instance());
if (m.m) {
m.m->isGlobal = isGlobal();
}
parse_module_config(m.get(), xml);
m.parse_config(xml);
m.m->parse_config(xml);
return m;
}
KSafeMark new_mark(const KString& name, const khttpd::KXmlNodeBody* xml) {
KModelPtr<KMark> new_mark(const KString& name, const khttpd::KXmlNodeBody* xml) {
auto it = KAccess::mark_factorys[type].find(name);
if (it == KAccess::mark_factorys[type].end()) {
return nullptr;
}
KSafeMark m((*it).second->new_instance());
if (m) {
m->isGlobal = isGlobal();
KModelPtr<KMark> m((*it).second->new_instance());
if (m.m) {
m.m->isGlobal = isGlobal();
}
parse_module_config(m.get(), xml);
m.parse_config(xml);
m.m->parse_config(xml);
return m;
}
kgl_ref_str_t get_qname() {
Expand Down Expand Up @@ -140,8 +141,8 @@ class KAccess final : public kconfig::KConfigListen
void inter_destroy();
void htmlChainAction(KWStream& s, kgl_jump_type jump_type, KJump* jump, bool showTable, const KString& skipTable);
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);
KSafeAcl get_named_acl(const KString& name);
KSafeMark get_named_mark(const KString& name);
KModelPtr<KAcl> get_named_acl(const KString& name);
KModelPtr<KMark> get_named_mark(const KString& name);
KFiberReadLocker read_lock() {
return KFiberReadLocker(rwlock);
}
Expand Down
50 changes: 39 additions & 11 deletions include/KChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <vector>
#include "kmalloc.h"
#include "KUrlValue.h"

#include "KModelPtr.h"
#define CHAIN_CONTEXT "chain"
class KAccess;

Expand All @@ -42,11 +42,11 @@ class KChain final
//OR NEXT
for (auto it = acls.begin(); it != acls.end(); ++it) {
if (result && last_or) {
last_or = (*it)->is_or;
last_or = (*it).is_or;
continue;
}
result = ((*it)->match(rq, obj) != (*it)->revers) ? KF_STATUS_REQ_TRUE : KF_STATUS_REQ_FALSE;
last_or = (*it)->is_or;
result = ((*it).m->match(rq, obj) != (*it).revers) ? KF_STATUS_REQ_TRUE : KF_STATUS_REQ_FALSE;
last_or = (*it).is_or;
if (!result && !last_or) {
break;
}
Expand All @@ -57,15 +57,15 @@ class KChain final
last_or = false;
for (auto it = marks.begin(); it != marks.end(); ++it) {
if (result && last_or) {
last_or = (*it)->is_or;
last_or = (*it).is_or;
continue;
}
result = (*it)->process(rq, obj, fo);
result = (*it).m->process(rq, obj, fo);
if (KBIT_TEST(result, KF_STATUS_REQ_FINISHED)) {
++hit_count;
return result;
}
result = (!!result != (*it)->revers) ? KF_STATUS_REQ_TRUE : KF_STATUS_REQ_FALSE;
result = (!!result != (*it).revers) ? KF_STATUS_REQ_TRUE : KF_STATUS_REQ_FALSE;
if (!result && !last_or) {
break;
}
Expand All @@ -91,13 +91,41 @@ class KChain final
private:
void get_edit_html(kgl::serializable* s);
void get_edit_html(KWStream& s, u_short accessType);
void getModelHtml(KModel* model, KWStream& s, int type, int index);
template<typename T>
void getModelHtml(KModelPtr<T> &ptr, KWStream& s, int type, int index) {
s << "<tr><td><input type=hidden name='begin_sub_form' value='"
<< (type == 0 ? "acl_"_CS : "mark_"_CS)
<< ptr.m->getName() << "'>";
s << "[<a href=\"javascript:delmodel('" << index << "'," << type << ");\">del</a>]";
if (ptr.named.empty()) {
s << "<input type = checkbox name = 'or' value = '1' ";
if (ptr.is_or) {
s << "checked";
}
s << ">OR";
s << "<input type=checkbox name='revers' value='1' ";
if (ptr.revers) {
s << "checked";
}
s << ">NOT ";
s << ptr.m->getName();
} else {
s << "named:" << ptr.named;
}
s << "</td><td>";
if (ptr.named.empty()) {
ptr.m->get_html(s);
} else {
s << "<input type='hidden' name='ref' value='" << ptr.named << "'/>";
s << "named model do not support";
}
s << "<input type=hidden name='end_sub_form' value='1'></td></tr>\n";
}
private:

uint32_t hit_count;
kgl_jump_type jump_type;
KSafeJump jump;
std::vector<KAcl*> acls;
std::vector<KMark*> marks;
std::vector<KModelPtr<KAcl>> acls;
std::vector<KModelPtr<KMark>> marks;
};
#endif /*KCHAIN_H_*/
19 changes: 8 additions & 11 deletions include/KModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ using KSafeSource = std::unique_ptr<KFetchObject>;
class KModel {
public:
KModel() {
revers = false;
is_or = false;
//revers = false;
//is_or = false;
isGlobal = true;
ref = 1;
}
Expand All @@ -60,12 +60,9 @@ class KModel {
}
}
void dump(kgl::serializable* m, bool is_short) {
m->add("revers", revers);
m->add("is_or", is_or);
//m->add("revers", revers);
//m->add("is_or", is_or);
m->add("module", getName());
if (!named.empty()) {
m->add("ref", named);
}
KStringBuf out;
if (is_short) {
get_display(out);
Expand All @@ -75,10 +72,10 @@ class KModel {
m->add("html", out.str());
}
/* 命名模块的名字 */
KString named;
bool revers;
bool is_or;
bool isGlobal;
//KString named;
//bool revers;
//bool is_or;
bool isGlobal;
protected:
volatile uint32_t ref;
virtual ~KModel() {
Expand Down
74 changes: 74 additions & 0 deletions include/KModelPtr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#ifndef KMODELPTR_H_INCLUDED
#define KMODELPTR_H_INCLUDED
#include "serializable.h"
template<typename T>
class KModelPtr {
public:
KModelPtr(T* m) {
revers = false;
is_or = false;
this->m = m;
}
KModelPtr(const KString& named, T* m) : named{ named } {
revers = false;
is_or = false;
if (!m) {
throw std::bad_exception();
}
this->m = m;
}
KModelPtr(const KModelPtr& ptr) :named{ ptr.named } {
if (ptr.m) {
this->m = static_cast<T*>(ptr.m->add_ref());
} else {
this->m = nullptr;
}
this->revers = ptr.revers;
this->is_or = ptr.is_or;
}
~KModelPtr() {
if (m) {
m->release();
}
}
explicit operator bool() const noexcept {
return m != nullptr;
}
KModelPtr& operator =(const KModelPtr& ptr) {
if (this == *ptr) {
return *this;
}
if (m) {
m->release();
m = nullptr;
}
if (ptr.m) {
this->m = static_cast<T*>(ptr.m->add_ref());
}
this->revers = ptr.revers;
this->is_or = ptr.is_or;
this->named = ptr.named;
return *this;
}
void parse_config(const khttpd::KXmlNodeBody* xml) {
revers = (xml->attributes["revers"] == "1");
is_or = (xml->attributes["or"] == "1");
//m->parse_config(xml);
}
void dump(kgl::serializable* m, bool is_short) {
m->add("revers", revers);
m->add("is_or", is_or);
if (!named.empty()) {
m->add("ref", named);
}
if (this->m) {
this->m->dump(m, is_short);
}
}
bool revers;
bool is_or;
/* ÃüÃûÄ£¿éµÄÃû×Ö */
KString named;
T* m;
};
#endif // !KMODELPTR_H_INCLUDED
37 changes: 8 additions & 29 deletions include/KNamedModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,16 @@
#include "KConfigTree.h"
#include "KModel.h"
#include "KSharedObj.h"
#include "KModelPtr.h"

class KNamedMark final: public KMark {
public:
KMark* new_instance() {
return static_cast<KMark *>(add_ref());
}
virtual const char* getName() override {
return mark->getName();
}
virtual void parse_config(const khttpd::KXmlNodeBody* xml) override {

}
virtual void parse_child(const kconfig::KXmlChanged* changed)override {
}
virtual void get_display(KWStream& s)override {
}
virtual void get_html(KWStream& s) override {
}
/* return KF_STATUS_REQ_FALSE, KF_STATUS_REQ_TRUE,KF_STATUS_REQ_FINISHED */
uint32_t process(KHttpRequest* rq, KHttpObject* obj, KSafeSource& fo) override {
return mark->process(rq, obj, fo);
}
private:
KSafeMark mark;
};
class KNamedModel : public kconfig::KConfigListen
{
public:
KNamedModel(KString name, const KSafeModel& model) : name{ name },m(model) {
ref = 1;
m->named = name;
}
KNamedModel(KString name, KModel *model) : name{ name }, m(model->add_ref()) {
ref = 1;
}
KNamedModel* add_ref() {
katom_inc((void*)&ref);
Expand All @@ -47,11 +26,11 @@ class KNamedModel : public kconfig::KConfigListen
KModel *get_module() {
return m.get();
}
KSafeAcl as_acl() {
return KSafeAcl(static_cast<KAcl *>(m->add_ref()));
KModelPtr<KAcl> as_acl() {
return KModelPtr<KAcl>(name, static_cast<KAcl *>(m.get()->add_ref()));
}
KSafeMark as_mark() {
return KSafeMark(static_cast<KMark*>(m->add_ref()));
KModelPtr<KMark> as_mark() {
return KModelPtr<KMark>(name, static_cast<KMark*>(m.get()->add_ref()));
}
kconfig::KConfigEventFlag config_flag() const {
return kconfig::ev_subdir;
Expand Down
Loading

0 comments on commit ab7e2a5

Please sign in to comment.