From a85c49cf9f7be4935972412d67bf2883f50aa555 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Fri, 28 Aug 2020 10:44:18 +0900 Subject: [PATCH 01/16] DSInput: add winX, winY and get/set APIs for DSInputTouchEvent/DSInputMouseEvent Change-Id: I9a937576f75580a1f13ab7308203bba51df5c5ca Signed-off-by: Sung-Jin Park --- src/DSInput/DSInput.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++---- src/DSInput/DSInputEvent.h | 15 +++++++++++++ 2 files changed, 67 insertions(+), 4 deletions(-) diff --git a/src/DSInput/DSInput.cpp b/src/DSInput/DSInput.cpp index 7a34779..f86c9cf 100644 --- a/src/DSInput/DSInput.cpp +++ b/src/DSInput/DSInput.cpp @@ -505,13 +505,13 @@ void DSInputKeyboardEvent::setKeyname(std::string name) DSInputMouseEvent::DSInputMouseEvent() : DSInputEvent(nullptr, NoneEvent, 0), - __button(0), __x(0), __y(0), __z(0) + __button(0), __x(0), __y(0), __z(0), __winX(0), __winY(0), __winZ(0) { } DSInputMouseEvent::DSInputMouseEvent(std::shared_ptr device, Type type, uint32_t timestamp, int button, int x, int y, int z) : DSInputEvent(device, type, timestamp), - __button(button), __x(x), __y(y), __z(z) + __button(button), __x(x), __y(y), __z(z), __winX(0), __winY(0), __winZ(0) { } @@ -540,16 +540,45 @@ const int DSInputMouseEvent::getZ() return __z; } +const int DSInputMouseEvent::getWinX() +{ + return __winX; +} + +const int DSInputMouseEvent::getWinY() +{ + return __winY; +} + +const int DSInputMouseEvent::getWinZ() +{ + return __winZ; +} + +void DSInputMouseEvent::setWinX(int winX) +{ + __winX = winX; +} + +void DSInputMouseEvent::setWinY(int winY) +{ + __winY = winY; +} + +void DSInputMouseEvent::setWinZ(int winZ) +{ + __winZ = winZ; +} DSInputTouchEvent::DSInputTouchEvent() : DSInputEvent(nullptr, NoneEvent, 0), - __index(0), __x(0), __y(0) + __index(0), __x(0), __y(0), __winX(0), __winY(0) { } DSInputTouchEvent::DSInputTouchEvent(std::shared_ptr device, Type type, uint32_t timestamp, int index, int x, int y) : DSInputEvent(device, type, timestamp), - __index(index), __x(x), __y(y) + __index(index), __x(x), __y(y), __winX(0), __winY(0) { } @@ -572,5 +601,24 @@ const int DSInputTouchEvent::getY() return __y; } +const int DSInputTouchEvent::getWinX() +{ + return __winX; +} + +const int DSInputTouchEvent::getWinY() +{ + return __winY; +} + +void DSInputTouchEvent::setWinX(int winX) +{ + __winX = winX; +} + +void DSInputTouchEvent::setWinY(int winY) +{ + __winY = winY; +} } // namespace display_server diff --git a/src/DSInput/DSInputEvent.h b/src/DSInput/DSInputEvent.h index aa12dc2..1df1f03 100644 --- a/src/DSInput/DSInputEvent.h +++ b/src/DSInput/DSInputEvent.h @@ -96,12 +96,21 @@ public: const int getX(); const int getY(); const int getZ(); + const int getWinX(); + const int getWinY(); + const int getWinZ(); + void setWinX(int winX); + void setWinY(int winY); + void setWinZ(int winZ); protected: int __button; int __x; int __y; int __z; + int __winX; + int __winY; + int __winZ; }; class DSInputTouchEvent : public DSInputEvent @@ -114,11 +123,17 @@ public: const int getIndex(); const int getX(); const int getY(); + const int getWinX(); + const int getWinY(); + void setWinX(int winX); + void setWinY(int winY); protected: int __index; int __x; int __y; + int __winX; + int __winY; }; } -- 2.7.4 From e4ed3575c1e231182da5b17154a1ac4965b9b951 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Fri, 28 Aug 2020 13:21:00 +0900 Subject: [PATCH 02/16] DSTouch: send touch event with winX, winY coordinates Change-Id: I5e19092c1797d2262dc608686a3bb64bb564b3f7 Signed-off-by: Sung-Jin Park --- src/DSSeat/DSTouch.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/DSSeat/DSTouch.cpp b/src/DSSeat/DSTouch.cpp index c636dd7..37b17fb 100644 --- a/src/DSSeat/DSTouch.cpp +++ b/src/DSSeat/DSTouch.cpp @@ -61,9 +61,10 @@ void DSTouch::processEvent(DSInputTouchEvent *ev, void *data) if (ev->getType() == DSInputEvent::TouchDownEvent) { - DSLOG_DBG("DSTouch", "[touchDown] devicename: %s, timestamp: %u\n", - ev->getDevice()->getName().c_str(), ev->getTimestamp()); - touchDown(ev->getIndex(), ev->getX(), ev->getY()); + DSLOG_DBG("DSTouch", "[touchDown] devicename: %s, timestamp: %u, x: %d (winX: %d), y: %d (winY: %d)\n", + ev->getDevice()->getName().c_str(), ev->getTimestamp(), + ev->getX(), ev->getWinX(), ev->getY(), ev->getWinY()); + touchDown(ev->getIndex(), ev->getWinX(), ev->getWinY()); } else if (ev->getType() == DSInputEvent::TouchUpEvent) { @@ -73,15 +74,16 @@ void DSTouch::processEvent(DSInputTouchEvent *ev, void *data) } else//DSInputEvent::TouchMoveEvent { - DSLOG_DBG("DSTouch", "[touchDown] devicename: %s, timestamp: %u\n", - ev->getDevice()->getName().c_str(), ev->getTimestamp()); - touchMove(ev->getIndex(), ev->getX(), ev->getY()); + DSLOG_DBG("DSTouch", "[touchDown] devicename: %s, timestamp: %u, x: %d (winX: %d), y: %d (winY: %d)\n", + ev->getDevice()->getName().c_str(), ev->getTimestamp(), + ev->getX(), ev->getWinX(), ev->getY(), ev->getWinY()); + touchMove(ev->getIndex(), ev->getWinX(), ev->getWinY()); } } void DSTouch::touchDown(int32_t id, int x, int y) { - if (__dswlTouch) + if (__touchFocus && __dswlTouch) { __dswlTouch->sendDown(id, x, y); } @@ -89,7 +91,7 @@ void DSTouch::touchDown(int32_t id, int x, int y) void DSTouch::touchUp(int32_t id) { - if (__dswlTouch) + if (__touchFocus && __dswlTouch) { __dswlTouch->sendUp(id); } @@ -97,7 +99,7 @@ void DSTouch::touchUp(int32_t id) void DSTouch::touchMove(int32_t id, int x, int y) { - if (__dswlTouch) + if (__touchFocus && __dswlTouch) { __dswlTouch->sendMotion(id, x, y); } -- 2.7.4 From ee75a26177296b0378f0da03ea20e4021f7db773 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Fri, 28 Aug 2020 13:21:25 +0900 Subject: [PATCH 03/16] DSPointer: send mouse event with winX, winY coordinates Change-Id: Ib327cdf2fd670cfc2cdbdef40bc78c56e7ff5a90 Signed-off-by: Sung-Jin Park --- src/DSSeat/DSPointer.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/DSSeat/DSPointer.cpp b/src/DSSeat/DSPointer.cpp index 12f3c0c..02e3b3b 100644 --- a/src/DSSeat/DSPointer.cpp +++ b/src/DSSeat/DSPointer.cpp @@ -63,9 +63,10 @@ void DSPointer::processEvent(DSInputMouseEvent *ev, void *data) if (ev->getType() == DSInputEvent::MouseInEvent) { - DSLOG_DBG("DSTouch", "[mouseIn] devicename: %s, timestamp: %u\n", - ev->getDevice()->getName().c_str(), ev->getTimestamp()); - mouseIn(ev->getX(), ev->getY()); + DSLOG_DBG("DSTouch", "[mouseIn] devicename: %s, timestamp: %u, x: %d (winX: %d), y: %d (winY: %d)\n", + ev->getDevice()->getName().c_str(), ev->getTimestamp(), + ev->getX(), ev->getWinX(), ev->getY(), ev->getWinY()); + mouseIn(ev->getWinX(), ev->getWinY()); } else if (ev->getType() == DSInputEvent::MouseOutEvent) { @@ -81,9 +82,10 @@ void DSPointer::processEvent(DSInputMouseEvent *ev, void *data) } else if (ev->getType() == DSInputEvent::MouseMoveEvent) { - DSLOG_DBG("DSTouch", "[mouseMove] devicename: %s, timestamp: %u\n", - ev->getDevice()->getName().c_str(), ev->getTimestamp()); - mouseMove(ev->getX(), ev->getY()); + DSLOG_DBG("DSTouch", "[mouseMove] devicename: %s, timestamp: %u, x: %d (winX: %d), y: %d (winY: %d)\n", + ev->getDevice()->getName().c_str(), ev->getTimestamp(), + ev->getX(), ev->getWinX(), ev->getY(), ev->getWinY()); + mouseMove(ev->getWinX(), ev->getWinY()); } else if (ev->getType() == DSInputEvent::MouseUpEvent) { @@ -100,7 +102,7 @@ void DSPointer::processEvent(DSInputMouseEvent *ev, void *data) void DSPointer::mouseDown(uint32_t button) { - if (__dswlPointer) + if (__ptrFocus && __dswlPointer) { __dswlPointer->sendButtonDown(button); } @@ -108,7 +110,7 @@ void DSPointer::mouseDown(uint32_t button) void DSPointer::mouseUp(uint32_t button) { - if (__dswlPointer) + if (__ptrFocus && __dswlPointer) { __dswlPointer->sendButtonUp(button); } @@ -116,7 +118,7 @@ void DSPointer::mouseUp(uint32_t button) void DSPointer::mouseMove(int x, int y) { - if (__dswlPointer) + if (__ptrFocus && __dswlPointer) { __dswlPointer->sendMotion(x, y); } -- 2.7.4 From 90ffb8cc80cbe5f6df404c51abcd01aef519c922 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Fri, 28 Aug 2020 13:22:13 +0900 Subject: [PATCH 04/16] DSWaylandPointer: fix to return if there is no resource for pointer Change-Id: I955b3a312323f3b3327f1bc67848ca137c160fd2 Signed-off-by: Sung-Jin Park --- src/DSWaylandServer/DSWaylandPointer.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/DSWaylandServer/DSWaylandPointer.cpp b/src/DSWaylandServer/DSWaylandPointer.cpp index 186c5cd..f298c43 100644 --- a/src/DSWaylandServer/DSWaylandPointer.cpp +++ b/src/DSWaylandServer/DSWaylandPointer.cpp @@ -124,6 +124,9 @@ void DSWaylandPointerPrivate::pointer_release(Resource *resource) void DSWaylandPointerPrivate::sendEnter(struct ::wl_resource *wlResource, struct ::wl_resource *surface, int surface_x, int surface_y) { + if (!__wlPointerResource) + return; + wl_fixed_t surface_x_fixed = wl_fixed_from_int(surface_x); wl_fixed_t surface_y_fixed = wl_fixed_from_int(surface_y); @@ -132,11 +135,17 @@ void DSWaylandPointerPrivate::sendEnter(struct ::wl_resource *wlResource, struct void DSWaylandPointerPrivate::sendLeave(struct ::wl_resource *wlResource, struct ::wl_resource *surface) { + if (!__wlPointerResource) + return; + send_leave(__wlPointerResource, __compositor->nextSerial(), surface); } void DSWaylandPointerPrivate::sendMotion(int surface_x, int surface_y) { + if (!__wlPointerResource) + return; + wl_fixed_t surface_x_fixed = wl_fixed_from_int(surface_x); wl_fixed_t surface_y_fixed = wl_fixed_from_int(surface_y); @@ -145,6 +154,9 @@ void DSWaylandPointerPrivate::sendMotion(int surface_x, int surface_y) void DSWaylandPointerPrivate::sendButton(uint32_t button, uint32_t state) { + if (!__wlPointerResource) + return; + send_button(__wlPointerResource, __compositor->nextSerial(), __seat->getCurrentEventTime(), button, state); } -- 2.7.4 From 19cc7a2f2f566cb06bee57990ed1f7def2b46246 Mon Sep 17 00:00:00 2001 From: Sung-Jin Park Date: Fri, 28 Aug 2020 13:23:37 +0900 Subject: [PATCH 05/16] DSSeat: set winX/winY before sending event(s) to touch/pointer Change-Id: I1254f9f1070118317d0007fa117381e9e3f34a31 Signed-off-by: Sung-Jin Park --- src/DSSeat/DSSeat.cpp | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/DSSeat/DSSeat.cpp b/src/DSSeat/DSSeat.cpp index 0030478..599d32b 100644 --- a/src/DSSeat/DSSeat.cpp +++ b/src/DSSeat/DSSeat.cpp @@ -425,7 +425,19 @@ void DSSeat::__onPointerEvent(DSInputMouseEvent *ev) //set the window as pointer focus window if (window) + { + int winX; + int winY; + stPosition pos; + + pos = window->getPosition(); + winX = ev->getX() - pos.x; + winY = ev->getY() - pos.y; + ev->setWinX(winX); + ev->setWinY(winY); + __pointer->setFocus(window); + } //send pointer enter to the new pointer focus window std::shared_ptr evMouseIn = std::make_shared(ev->getDevice(), DSInputEvent::MouseInEvent, ev->getTimestamp(), ev->getButton(), 0, 0, 0); @@ -454,7 +466,19 @@ void DSSeat::__onTouchEvent(DSInputTouchEvent *ev) //set the window as touch focus window if (window) + { + int winX; + int winY; + stPosition pos; + + pos = window->getPosition(); + winX = ev->getX() - pos.x; + winY = ev->getY() - pos.y; + ev->setWinX(winX); + ev->setWinY(winY); + __touch->setFocus(window); + } //TODO : emit touch focus changed signal } -- 2.7.4 From 665b841b86489f4315a776cf59b4af6c5734a590 Mon Sep 17 00:00:00 2001 From: dyamy-lee Date: Thu, 20 Aug 2020 12:49:43 +0900 Subject: [PATCH 06/16] add code for TraceProtocol checked rule init with file. logs are alot. -> It should be removed almost for readablilty add rule_print_func as DSLOG_INF -> It should be printed Change-Id: I11985d3e0420758c7f641ec7e4b1ba6187f5afc0 --- src/DSWaylandServer/DSWaylandProtocolTrace.cpp | 1436 +++++++++++++++++++- src/DSWaylandServer/DSWaylandProtocolTrace.h | 1 + .../DSWaylandProtocolTracePrivate.h | 246 +++- 3 files changed, 1674 insertions(+), 9 deletions(-) diff --git a/src/DSWaylandServer/DSWaylandProtocolTrace.cpp b/src/DSWaylandServer/DSWaylandProtocolTrace.cpp index 0f8c9a6..fe89016 100644 --- a/src/DSWaylandServer/DSWaylandProtocolTrace.cpp +++ b/src/DSWaylandServer/DSWaylandProtocolTrace.cpp @@ -23,6 +23,8 @@ #include "DSWaylandProtocolTrace.h" #include "DSWaylandProtocolTracePrivate.h" +#include +#include namespace display_server { @@ -31,10 +33,69 @@ int DSWaylandProtocolTrace::__refCount { 0 }; std::mutex DSWaylandProtocolTrace::__mutex; DSWaylandProtocolTrace* DSWaylandProtocolTrace::__protocolTrace { nullptr }; +static FILE *log_fp_ptrace = NULL; +static struct wl_protocol_logger *ds_wl_protocol_logger; +static ProtocolTrace_Rule_Checker *rc = nullptr; + +static struct +{ + const char *token_char; + const int token_length; + ProtocolTrace_Token token_name; +} token_table[] = +{ + {"\0", 1, PROTOCOLTRACE_TOKEN_EOS}, + {"\t", 1, PROTOCOLTRACE_TOKEN_SPACE}, + {" ", 1, PROTOCOLTRACE_TOKEN_SPACE}, + {"!=", 2, PROTOCOLTRACE_TOKEN_NOT_EQ}, + {"&", 1, PROTOCOLTRACE_TOKEN_AND}, + {"&&", 2, PROTOCOLTRACE_TOKEN_AND}, + {"(", 1, PROTOCOLTRACE_TOKEN_L_BR}, + {")", 1, PROTOCOLTRACE_TOKEN_R_BR}, + {"<", 1, PROTOCOLTRACE_TOKEN_LSS_THAN}, + {"<=", 2, PROTOCOLTRACE_TOKEN_LSS_EQ}, + {"<>", 2, PROTOCOLTRACE_TOKEN_NOT_EQ}, + {"=", 1, PROTOCOLTRACE_TOKEN_EQUAL}, + {"==", 2, PROTOCOLTRACE_TOKEN_EQUAL}, + {">", 1, PROTOCOLTRACE_TOKEN_GRT_THAN}, + {">=", 2, PROTOCOLTRACE_TOKEN_GRT_EQ}, + {"and", 3, PROTOCOLTRACE_TOKEN_AND}, + {"or", 2, PROTOCOLTRACE_TOKEN_OR}, + {"|", 1, PROTOCOLTRACE_TOKEN_OR}, + {"||", 2, PROTOCOLTRACE_TOKEN_OR}, +}; + +const char *get_next_argument(const char *signature, struct argument_details *details) +{ + details->nullable = 0; + for(; *signature; ++signature) + { + switch(*signature) + { + case 'i': + case 'u': + case 'f': + case 's': + case 'o': + case 'n': + case 'a': + case 'h': + details->type = *signature; + return signature +1; + case '?': + details->nullable = 1; + } + } + details->type = '\0'; + return signature; +} + DSWaylandProtocolTrace::DSWaylandProtocolTrace(DSObject *parent) : DS_INIT_PRIVATE_PTR(DSWaylandProtocolTrace) { //init(); + DS_GET_PRIV(DSWaylandProtocolTrace); + priv->__wlCompositor = DSWaylandCompositor::getInstance(); } DSWaylandProtocolTrace::~DSWaylandProtocolTrace() @@ -74,12 +135,72 @@ void DSWaylandProtocolTrace::releaseInstance() bool DSWaylandProtocolTrace::init(void) { - return false; + DS_GET_PRIV(DSWaylandProtocolTrace); + bool ret = false; + char *env_path = nullptr; + char tmp[PATH_MAX] = {0,}; + + rc = priv->rulechecker_init(); + + // set rule file path + env_path = getenv("E_INFO_RULE_FILE"); + DSLOG_DBG("DSWaylandProtocolTrace", "========================== rule file path = %s", env_path); + ret = priv->protocol_rule_init(env_path); + DSLOG_DBG("DSWaylandProtocolTrace", "result of protocol rule init = %d", ret); + + if(env_path) + { + DSLOG_DBG("DSWaylandProtocolTrace", "delete rule file path = %s", env_path); + //delete env_path; + //free(env_path); + env_path = nullptr; + DSLOG_DBG("DSWaylandProtocolTrace", "delete rule file path done."); + } + if(!ret) return ret; + + // set trace file path + DSLOG_DBG("DSWaylandProtocolTrace", "===================================================="); + env_path = getenv("E_INFO_TRACE_FILE"); + DSLOG_DBG("DSWaylandProtocolTrace", "========================== trace file path = %s", env_path); + ret = priv->protocol_trace_init(env_path); + DSLOG_DBG("DSWaylandProtocolTrace", "result of protocol trace init = %d", ret); + if(env_path) + { + DSLOG_DBG("DSWaylandProtocolTrace", "delete trace file path = %s", env_path); + //delete env_path; + //free(env_path); + env_path = nullptr; + DSLOG_DBG("DSWaylandProtocolTrace", "delete trace file path done."); + } + return ret; } int DSWaylandProtocolTrace::enableProtocolTrace(bool state) { + DS_GET_PRIV(DSWaylandProtocolTrace); //following state : enable, disable trace + DSLOG_DBG("DSWaylandProtocolTrace", "state = %d", state); + + if(log_fp_ptrace != nullptr) + { + fclose(log_fp_ptrace); + log_fp_ptrace = nullptr; + } + + if(state) + { + //TODO: can change trace file path by cmd + DSLOG_DBG("DSWaylandProtocolTrace", "state true == %d", state); + priv->protocol_trace_set(); + return 1; + } + else + { + DSLOG_DBG("DSWaylandProtocolTrace", "state false == %d", state); + priv->protocol_trace_unset(); + return 0; + } + return -1; } @@ -94,20 +215,1325 @@ DSWaylandProtocolTracePrivate::~DSWaylandProtocolTracePrivate() } -void DSWaylandProtocolTracePrivate::protocol_rule_init(char *rule_path) +bool DSWaylandProtocolTracePrivate::protocol_rule_init(char *rule_path) +{ + char *argv[2]; + int argc = 2; + + if(!rule_path || strlen(rule_path) <= 0) + return false; + + argv[0] = "file"; + argv[1] = rule_path; + + DSLOG_DBG("DSWaylandProtocolTracePriv", "rule_path = %s", rule_path); + + protocol_rule_set(argc, (const char**)&(argv[0])); + + return true; +} + +bool DSWaylandProtocolTracePrivate::protocol_trace_init(char *trace_path) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> protocol_trace_init"); + if(!trace_path || strlen(trace_path) <= 0) + return false; + + trace_env_path = trace_path; + DSLOG_DBG("DSWaylandProtocolTracePriv", "saved trace path = %s", trace_env_path); + + //enable + protocol_trace_set(); + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << protocol_trace_init"); + /* + log_fp_ptrace = fopen(trace_path, "a"); + + setvbuf(log_fp_ptrace, NULL, _IOLBF, 512); + + if(ds_wl_protocol_logger) + { + wl_protocol_logger_destroy(ds_wl_protocol_logger); + ds_wl_protocol_logger = NULL; + } + ::wl_display *display; + display = __wlCompositor->display(); + ds_wl_protocol_logger = wl_display_add_protocol_logger(display, protocol_trace_func, nullptr); + */ + return true; +} + +bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char **argv) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> protocol_rule_set"); + const char * command; + + if(argc == 0) + { + rulechecker_rule_print(rc); + return true; + } + + command = argv[0]; + + if(!strcasecmp(command, "add")) + { + DSLOG_DBG("DSWaylandProtocolTracePriv", "ADD"); + ProtocolTrace_Policy_Type policy_type; + ProtocolTrace_Rule_Set_Result result; + const char * policy = argv[1]; //allow, deny + char merge[8192] = {0,}, rule[8192] = {0,}; + int i, index=0, size_rule, apply = 0; + + if(argc <3) + { + DSLOG_ERR("DSWaylandProtocolTracePriv", "Error: Too few argumens."); + //REPLY("Error : Too few arguments."); + return false; + } + DSLOG_DBG("DSWaylandProtocolTracePriv", "ADD :: go on"); + + if(!strcasecmp(policy, "ALLOW")) + policy_type = PROTOCOLTRACE_TYPE_ALLOW; + else if(!strcasecmp(policy, "DENY")) + policy_type = PROTOCOLTRACE_TYPE_DENY; + else + { + DSLOG_ERR("DSWaylandProtocolTracePriv", "Error : Unknown policy : [%s].\n Policy should be ALLOW or DENY.", policy); + //REPLY; + return false; + } + DSLOG_DBG("DSWaylandProtocolTracePriv", "ADD :: policy_type = %d", policy_type); + + // protocol arguments merge + protocol_arguments_merge(merge, sizeof(merge), argc -2, &(argv[2])); + DSLOG_DBG("DSWaylandProtocolTracePriv", "ADD :: merge = %s", merge); + + size_rule = sizeof(rule) -1; + DSLOG_DBG("DSWaylandProtocolTracePriv", "ADD :: size_rule = %d", size_rule); + + for(i=0; i size_rule) + return false; + continue; + } + if(merge[i] == '+') + { + rule[index++] = ' '; + if(index > size_rule) + return false; + if(apply ==0) + { + const char * plus = "|| type=reply || type=error"; + int len = MIN(size_rule - index, strlen(plus)); + strncat(rule, plus, len); + index += len; + if(index >size_rule) + return false; + apply =1; + } + continue; + } + rule[index++] = merge[i]; + DSLOG_DBG("DSWaylandProtocolTracePriv", "ADD :: rule[%d] = %c", index-1, rule[index-1]); + if(index >size_rule) + return false; + } + DSLOG_DBG("DSWaylandProtocolTracePriv", "ADD :: rule = %s", rule); + + DSLOG_DBG("DSWaylandProtocolTracePriv", "ADD :: rulechecker_rule_add (before) -> rc %d",rc->count); + result = rulechecker_rule_add(rc, policy_type, rule); + DSLOG_DBG("DSWaylandProtocolTracePriv", "ADD :: rulechecker_rule_add (after) -> rc %d",rc->count); + + if(result == PROTOCOLTRACE_RULE_SET_ERR_TOO_MANY_RULES) + { + DSLOG_ERR("DSWaylandProtocolTracePriv", "Error: Too many rules were added."); + return false; + } + else if(result == PROTOCOLTRACE_RULE_SET_ERR_PARSE) + { + DSLOG_ERR("DSWaylandProtocolTracePriv", "Error: An error occured during parsing the rule [%s]", rule); + return false; + } + DSLOG_INF("DSWaylandProtocolTracePriv", "The rule was successfully added"); + rulechecker_rule_print(rc); + + return true; + } + else if(!strcasecmp(command, "remove")) + { + DSLOG_DBG("DSWaylandProtocolTracePriv", "REMOVE"); + const char * remove_idx; + int i; + + if(argc < 2) + { + DSLOG_ERR("DSWaylandProtocolTracePriv", "Error: Too few arguments"); + return false; + } + + for(i =0; icount); + rulechecker_destroy(rc); + rc = rulechecker_init(); + if(!rc) + { + DSLOG_ERR("DSWaylandProtocolTracePriv", "Error: rules not removed"); + return false; + } + DSLOG_DBG("DSWaylandProtocolTracePriv", "REMOVE :: (after destroy) rc = %d", rc->count); + DSLOG_INF("DSWaylandProtocolTracePriv", "Every rules were successfully removed"); + } + else + { + int index = atoi(remove_idx); + DSLOG_DBG("DSWaylandProtocolTracePriv", "REMOVE :: remove idx = %d", index); + + DSLOG_DBG("DSWaylandProtocolTracePriv", "REMOVE :: (before rulechecker_rule_remove) rc = %d", rc->count); + if(isdigit(*remove_idx) && rulechecker_rule_remove(rc, index) == 0) + DSLOG_INF("DSWaylandProtocolTracePriv", "The rule [%d] was successfully removed.", index); + else + DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : No such rule [%s]", remove_idx); + + DSLOG_DBG("DSWaylandProtocolTracePriv", "REMOVE :: (after rulechecker_rule_remove) rc = %d", rc->count); + } + } + rulechecker_rule_print(rc); + } + else if(!strcasecmp(command, "file")) + { + DSLOG_DBG("DSWaylandProtocolTracePriv", "FILE"); + if(argc <2) + { + DSLOG_ERR("DSWaylandProtocolTracePriv", "Error: Too few argumens."); + //REPLY("Error : Too few arguments."); + return false; + } + if(!protocol_rule_file_set(argv[1])) + return false; + + rulechecker_rule_print(rc); + + return true; + } + else if(!strcasecmp(command, "print")) + { + rulechecker_rule_print(rc); + return true; + } + else if(!strcasecmp(command, "help")) + { + DSLOG_INF("DSWaylandProtocolTracePriv", "%s", rulechecker_usage_print()); + return true; + } + + DSLOG_ERR("DSWaylandProtocolTracePriv", "%s\nUnkown command : [%s] ", rulechecker_usage_print(), command); + + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << protocol_rule_set"); + + return true; +} + +bool DSWaylandProtocolTracePrivate::protocol_rule_file_set(const char *filename) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> protocol_rule_file_set"); + int fd = -1, rule_len; + char fs[8096], *pfs; + + fd = open(filename, O_RDONLY); + if(fd<0) + { + DSLOG_DBG("DSWaylandProtocolTracePriv", "failed: open '%s'", filename); + return false; + } + + rule_len = read(fd, fs, sizeof(fs)); + pfs = fs; + + while(pfs -fs < rule_len) + { + int i, new_argc =3; + char *new_argv[3] = {"add", }; + char policy[64] = {0,}; + char rule[1024] = {0,}; + + if(pfs[0] == ' ' || pfs[0] == '\n') + { + pfs++; + continue; + } + for(i=0; pfs[i] != ' '; i++) + policy[i] = pfs[i]; + + new_argv[1] = policy; + pfs += (strlen(new_argv[1])+1); + + memset(rule, 0, sizeof(rule)); + for(i=0; pfs[i]!='\n'; i++) + rule[i] = pfs[i]; + + new_argv[2] = rule; + + pfs += (strlen(new_argv[2]) +1); + + if(!protocol_rule_set((const int) new_argc, (const char**) new_argv)) + { + close(fd); + return false; + } + } + close(fd); + + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << protocol_rule_file_set"); + return true; +} + +bool DSWaylandProtocolTracePrivate::protocol_rule_validate(ProtocolTrace_Protocol_Log *log) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> protocol_rule_validate << "); + char *cmd = ""; + + if(!rc) + return false; + + cmd = protocol_cmd_get(log->cmd); + + return rulechecker_rule_validate(rc, log->type, log->target_id, log->name, log->client_pid, cmd); +} + +void DSWaylandProtocolTracePrivate::protocol_trace_set(void) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv","IN >> protocol trace set"); + log_fp_ptrace = fopen(trace_env_path, "a"); + if(!log_fp_ptrace) + { + DSLOG_ERR("DSWaylandProtocolTracePriv","failed open file(%s)", trace_env_path); + return; + } + setvbuf(log_fp_ptrace, NULL, _IOLBF, 512); + DSLOG_DBG("DSWaylandProtocolTracePriv","has log_fp_ptrace"); + + if(ds_wl_protocol_logger) + { + DSLOG_DBG("DSWaylandProtocolTracePriv","if has ds_wl_protocol_logger -> destroy"); + wl_protocol_logger_destroy(ds_wl_protocol_logger); + ds_wl_protocol_logger = NULL; + } + ::wl_display *display; + display = __wlCompositor->display(); + DSLOG_DBG("DSWaylandProtocolTracePriv","get display "); + + ds_wl_protocol_logger = wl_display_add_protocol_logger(display, protocol_trace_func, nullptr); + DSLOG_DBG("DSWaylandProtocolTracePriv","OUT << protocol trace set"); +} + +void DSWaylandProtocolTracePrivate::protocol_trace_unset(void) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv","IN >> protocol_trace_unset"); + if(ds_wl_protocol_logger) + { + wl_protocol_logger_destroy(ds_wl_protocol_logger); + ds_wl_protocol_logger = NULL; + } + DSLOG_DBG("DSWaylandProtocolTracePriv","OUT << protocol_trace_unset"); +} + +void DSWaylandProtocolTracePrivate::wl_protocol_cb_client_destroy(struct wl_listener *listener, void *data) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv","IN >> wl_protocol_cb_client_destroy"); + + struct wl_client *wc = (struct wl_client *)data; + struct timespec tp; + unsigned int time; + pid_t client_pid =-1; + + + char strbuf[512], *str_buff = strbuf; + int str_r, str_l; + + str_buff[0] = '\0'; + str_r = sizeof(strbuf); + + wl_client_get_credentials(wc, &client_pid, nullptr, nullptr); + + clock_gettime(CLOCK_MONOTONIC, &tp); + time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000); + + //TODO: get client name + BUF_SNPRINTF("[%10.3f] Server [PID:%d] client destroying", time/1000.0, client_pid); + + if(log_fp_ptrace) + fprintf(log_fp_ptrace, "%s\n", strbuf); + else + DSLOG_INF("DSWaylandProtocolTracePriv", "%s", strbuf); + + wl_list_remove(&listener->link); + //free(listener); + delete listener; + listener = nullptr; + + DSLOG_DBG("DSWaylandProtocolTracePriv","OUT << wl_protocol_cb_client_destroy"); + +} + +void DSWaylandProtocolTracePrivate::protocol_client_destroy_listener_reg(struct wl_client *client) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv","IN >> protocol_client_destroy_listener_reg"); + + struct wl_listener *destroy_listener; + + destroy_listener = wl_client_get_destroy_listener(client, wl_protocol_cb_client_destroy); + if(destroy_listener) return; + + destroy_listener = (struct wl_listener *)calloc(1, sizeof(wl_listener)); + //EINA_SAFETY_ON_NULL_RETURN(destroy_listener); + + destroy_listener->notify = wl_protocol_cb_client_destroy; + wl_client_add_destroy_listener(client, destroy_listener); + + DSLOG_DBG("DSWaylandProtocolTracePriv","OUT << protocol_client_destroy_listener_reg"); +} + +void DSWaylandProtocolTracePrivate::protocol_trace_func(void *user_data, enum wl_protocol_logger_type direction, const struct wl_protocol_logger_message *message) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv","IN >> protocol_trace_func"); + + int i; + struct argument_details arg; + struct wl_client *wc = wl_resource_get_client(message->resource); + const char *signature = message->message->signature; + pid_t client_pid = -1; + struct timespec tp; + unsigned int time; + + char strbuf[512], *str_buff = strbuf; + int str_r, str_l; + + str_buff[0] = '\0'; + str_r = sizeof(strbuf); + + if(wc) + { + DSLOG_DBG("DSWaylandProtocolTracePriv","has wl_client"); + protocol_client_destroy_listener_reg(wc); + wl_client_get_credentials(wc, &client_pid, nullptr, nullptr); + } + + DSLOG_DBG("DSWaylandProtocolTracePriv","go on"); + + clock_gettime(CLOCK_MONOTONIC, &tp); + time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000); + + ProtocolTrace_Protocol_Log elog = {PROTOCOL_TYPE_REQUEST,}; + DSLOG_DBG("DSWaylandProtocolTracePriv", "before get info protocol log => type: %s, client_pit: %d, target_id: %d, name: %s, cmd: %s", elog.type, elog.client_pid, elog.target_id, elog.name, elog.cmd); + elog.type = (direction == WL_PROTOCOL_LOGGER_EVENT)? PROTOCOL_TYPE_EVENT:PROTOCOL_TYPE_REQUEST; + elog.client_pid = client_pid; + elog.target_id = wl_resource_get_id(message->resource); + snprintf(elog.name, PATH_MAX,"%s:%s", wl_resource_get_class(message->resource), message->message->name); + + DSLOG_DBG("DSWaylandProtocolTracePriv", "after get info protocol log => type: %s, client_pit: %d, target_id: %d, name: %s, cmd: %s", elog.type, elog.client_pid, elog.target_id, elog.name, elog.cmd); + + if(!protocol_rule_validate(&elog)) return; + + BUF_SNPRINTF("[%10.3f] %s%d%s%s@%u.%s(", + time / 1000.0, + elog.type ? "Server->Client [PID:" : "Server<-Client [PID:", + client_pid, "]", + wl_resource_get_class(message->resource), + wl_resource_get_id(message->resource), + message->message->name); + + for (i=0; iarguments_count; i++) + { + signature = get_next_argument(signature, &arg); + if(i>0) BUF_SNPRINTF(", "); + + switch(arg.type) + { + case 'u': + BUF_SNPRINTF("%u", message->arguments[i].u); + break; + case 'i': + BUF_SNPRINTF("%i", message->arguments[i].i); + break; + case 'f': + BUF_SNPRINTF("%f", wl_fixed_to_double(message->arguments[i].f)); + break; + case 's': + BUF_SNPRINTF("\"%s\"", message->arguments[i].s); + break; + case 'o': + if(message->arguments[i].o) + BUF_SNPRINTF("%s@%u", wl_resource_get_class((struct wl_resource*)message->arguments[i].o), + wl_resource_get_id((struct wl_resource*)message->arguments[i].o)); + else + BUF_SNPRINTF("nil"); + break; + case 'n': + BUF_SNPRINTF("new id %s@", (message->message->types[i]) ? message->message->types[i]->name : "[unknown]"); + if(message->arguments[i].n != 0) + BUF_SNPRINTF("%u", message->arguments[i].n); + else + BUF_SNPRINTF("nil"); + break; + case 'a': + BUF_SNPRINTF("array"); + break; + case 'h': + BUF_SNPRINTF("fd %d", message->arguments[i].h); + break; + } + } + + BUF_SNPRINTF("), cmd: %s", elog.cmd ? elog.cmd : "cmd is NULL"); + + if(log_fp_ptrace) + fprintf(log_fp_ptrace, "%s\n", strbuf); + else + DSLOG_INF("DSWaylandProtocolTracePriv","%s", strbuf); + + DSLOG_DBG("DSWaylandProtocolTracePriv","OUT << protocol_trace_func"); + +} + +ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::bintree_create_node(ProtocolTrace_Tree *tree) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv","IN >> bintree_create_node"); + + ProtocolTrace_Tree_Node *node = (ProtocolTrace_Tree_Node*) calloc(1, sizeof(ProtocolTrace_Tree_Node) + tree->size); + // enia safety + + node->left = nullptr; + node->right = nullptr; + + DSLOG_DBG("DSWaylandProtocolTracePriv","OUT << bintree_create_node"); + return node; +} + +ProtocolTrace_Tree *DSWaylandProtocolTracePrivate::bintree_create_tree(int size) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_create_tree"); + + ProtocolTrace_Tree *tree = (ProtocolTrace_Tree *)calloc(1, sizeof(ProtocolTrace_Tree) + size); + // eina safety + + tree->size = size; + tree->head = nullptr; + DSLOG_DBG("DSWaylandProtocolTracePriv", "bintree create treee => size : %d", tree->size); + + DSLOG_DBG("DSWaylandProtocolTracePriv","OUT << bintree_create_tree"); + + return tree; +} + +void DSWaylandProtocolTracePrivate::bintree_destroy_tree(ProtocolTrace_Tree *tree) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_destroy_tree"); + if(tree->head) + bintree_remove_node_recursive(tree->head); + //free(tree); + delete tree; + + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << bintree_destroy_tree"); +} + +ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::bintree_get_head(ProtocolTrace_Tree *tree) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_get_head >> OUT"); + return tree->head; +} + +ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::bintree_get_left_child(ProtocolTrace_Tree_Node *node) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_get_left_child >> OUT"); + return node->left; +} + +void *DSWaylandProtocolTracePrivate::bintree_get_node_data(ProtocolTrace_Tree_Node *node) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_get_node_data >> OUT"); + return (void*)(node+1); +} + +ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::bintree_get_right_child(ProtocolTrace_Tree_Node *node) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_get_right_child >> OUT"); + return node->right; +} + +void DSWaylandProtocolTracePrivate::bintree_inorder_traverse(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Traverse_Cb func, void *arg) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_inorder_traverse"); + if(tree->head) + bintree_inorder_traverse_recursive(tree, tree->head, tree->head, func, arg); + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << bintree_inorder_traverse"); +} + +int DSWaylandProtocolTracePrivate::bintree_inorder_traverse_recursive(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, ProtocolTrace_Tree_Traverse_Cb func, void *arg) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_inorder_traverse_recursive >> "); + if(node->left) + if(bintree_inorder_traverse_recursive(tree, node->left, node, func, arg)!=0) + return 1; + + if(func(tree, node, parent, arg)) + return 1; + + if(node->right) + if(bintree_inorder_traverse_recursive(tree,node->right, node, func, arg)!=0) + return 1; + return 0; +} + +void DSWaylandProtocolTracePrivate::bintree_postorder_traverse(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Traverse_Cb func, void *arg) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_postorder_traverse"); + if(tree->head) + bintree_postorder_traverse_recursive(tree, tree->head, tree->head, func, arg); + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << bintree_postorder_traverse"); +} + +int DSWaylandProtocolTracePrivate::bintree_postorder_traverse_recursive(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, ProtocolTrace_Tree_Traverse_Cb func, void *arg) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_postorder_traverse_recursive >> "); + if(node->left) + if(bintree_postorder_traverse_recursive(tree, node->left, node, func, arg)!=0) + return 1; + if(node->right) + if(bintree_postorder_traverse_recursive(tree, node->right, node, func, arg)!=0) + return 1; + + return func(tree, node,parent, arg); +} + +void DSWaylandProtocolTracePrivate::bintree_remove_node(ProtocolTrace_Tree_Node *node) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_remove_node"); + //free(node); + delete node; + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << bintree_remove_node"); +} + +void DSWaylandProtocolTracePrivate::bintree_remove_node_recursive(ProtocolTrace_Tree_Node *node) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_remove_node_recursive"); + if(node->left) + bintree_remove_node_recursive(node->left); + if(node->right) + bintree_remove_node_recursive(node->right); + + bintree_remove_node(node); + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << bintree_remove_node_recursive"); +} + +void DSWaylandProtocolTracePrivate::bintree_set_head(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *head) { + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_set_head"); + tree->head = head; + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << bintree_set_head"); } -void DSWaylandProtocolTracePrivate::protocol_trace_init(char *trace_path) +void DSWaylandProtocolTracePrivate::bintree_set_left_child(ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *child) { + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_set_left_child"); + node->left = child; + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << bintree_set_left_child"); +} + +void DSWaylandProtocolTracePrivate::bintree_set_right_child(ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *child) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_set_right_child"); + node->right = child; + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << bintree_set_right_child"); +} + +ProtocolTrace_Token DSWaylandProtocolTracePrivate::parser_next_token_get(const char **string) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> parser_next_token_get"); + DSLOG_DBG("DSWaylandProtocolTracePriv", "parameter string = %s",*string); + + static int token_cnt = sizeof(token_table) / sizeof(token_table[0]); + int i, compare_res, found =0, first, last; + + first = 0; + last = token_cnt -1; + + i = (first + last) /2; + while(1) + { + compare_res = strncmp(*string, token_table[i].token_char, token_table[i].token_length); + DSLOG_DBG("DSWaylandProtocolTracePriv", "parser_next_token_get:: i = %d// compare string -> string = %s ,vs, token_char = %s",i,*string, token_table[i].token_char); + while(compare_res == 0) + { + found = 1; + i++; + if(i==token_cnt) + break; + compare_res = strncmp(*string, token_table[i].token_char, token_table[i].token_length); + } + + if(found) + { + i--; + DSLOG_DBG("DSWaylandProtocolTracePriv", "parm string (before)=> %s",*string); + *string += token_table[i].token_length; + DSLOG_DBG("DSWaylandProtocolTracePriv", "parm string (after = add token length) => %s",*string); + DSLOG_DBG("DSWaylandProtocolTracePriv", "parser next token => %d, token_table name = %d",i,token_table[i].token_name); + return token_table[i].token_name; + } + + if(first >= last) + break; + + if(compare_res > 0) + first = i+1; + else + last = i-1; + + i = (first + last) /2; + + } + if(isalpha(**string)) + { + (*string)++; + DSLOG_DBG("DSWaylandProtocolTracePriv", "string is alpha >> next? = %c",**string); + while(isalpha(**string) || isdigit(**string) || **string == '_' || **string == '-') + { + (*string)++; + } + DSLOG_DBG("DSWaylandProtocolTracePriv", "string is alpha >> end alpha = %c",**string); + + return PROTOCOLTRACE_TOKEN_SYMBOL; + } + if(isdigit(**string)) + { + DSLOG_DBG("DSWaylandProtocolTracePriv", "string is digit = %c",**string); + (*string)++; + while(isdigit(**string)) + (*string)++; + + return PROTOCOLTRACE_TOKEN_NUMBER; + } + + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << parser_next_token_get"); + return PROTOCOLTRACE_TOKEN_UNKNOWN; } -void DSWaylandProtocolTracePrivate::protocol_rule_set(void) +ProtocolTrace_Tree *DSWaylandProtocolTracePrivate::protocol_parser_rule_string_parse(const char *string) { + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> protocol_parser_rule_string_parse"); + DSLOG_DBG("DSWaylandProtocolTracePriv", "parameter string = %s", string); + + ProtocolTrace_Tree *tree; + ProtocolTrace_Tree_Node *node; + ProtocolTrace_Token_Data token; + + token.string = &string; + DSLOG_DBG("DSWaylandProtocolTracePriv", "token = %s", *token.string); + parser_token_process(&token); + DSLOG_DBG("DSWaylandProtocolTracePriv", "token(after parser) = %s, %d", *token.string, token.last_token); + + tree = bintree_create_tree(sizeof(ProtocolTrace_Rule_Node)); + if(!tree) return nullptr; + + node = parser_token_parse(tree, &token); + DSLOG_DBG("DSWaylandProtocolTracePriv", "get node"); + + if(!node) + { + DSLOG_DBG("DSWaylandProtocolTracePriv", "node is null"); + bintree_destroy_tree(tree); + DSLOG_DBG("DSWaylandProtocolTracePriv", "finish destroy tree & return null"); + return nullptr; + } + + bintree_set_head(tree, node); + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << protocol_parser_rule_string_parse "); + + return tree; } -void DSWaylandProtocolTracePrivate::protocol_rule_file_set(void) +ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::parser_statement_parse(ProtocolTrace_Tree *tree, ProtocolTrace_Token_Data *token) { + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> parser_statement_parse"); + DSLOG_DBG("DSWaylandProtocolTracePriv", "(parameter) token->string = %s, token->last symbol =%s", *token->string, token->last_symbol); + DSLOG_DBG("DSWaylandProtocolTracePriv", "(parameter) tree_size = %d", tree->size); + + ProtocolTrace_Tree_Node *node = nullptr; + ProtocolTrace_Rule_Node *data; + + if(token->last_token == PROTOCOLTRACE_TOKEN_L_BR) + { + DSLOG_DBG("DSWaylandProtocolTracePriv", "last token = %d", PROTOCOLTRACE_TOKEN_L_BR); + parser_token_process(token); + + node = parser_token_parse(tree, token); + if(!node) + return nullptr; + + if(token->last_token != PROTOCOLTRACE_TOKEN_R_BR) + goto fail; + + DSLOG_DBG("DSWaylandProtocolTracePriv", "not fail"); + parser_token_process(token); + + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << parser_statement_parse"); + return node; + } + + if(token->last_token != PROTOCOLTRACE_TOKEN_SYMBOL) + goto fail; + + node = bintree_create_node(tree); + //eina safty + + data = (ProtocolTrace_Rule_Node *) bintree_get_node_data(node); + + strncpy(data->variable_name, token->last_symbol, token->symbol_len); + data->variable_name[token->symbol_len] = '\0'; + + if(!strcasecmp(data->variable_name, "all")) + { + DSLOG_DBG("DSWaylandProtocolTracePriv", "data = all"); + data->node_type = PROTOCOLTRACE_NODE_TYPE_ALL; + parser_token_process(token); + + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << parser_statement_parse"); + return node; + } + + data->node_type = PROTOCOLTRACE_NODE_TYPE_DATA; + + parser_token_process(token); + + switch(token->last_token) + { + case PROTOCOLTRACE_TOKEN_NOT_EQ: + data->comparer = PROTOCOLTRACE_COMPARER_NOT_EQ; + break; + case PROTOCOLTRACE_TOKEN_EQUAL: + data->comparer = PROTOCOLTRACE_COMPARER_EQUAL; + break; + case PROTOCOLTRACE_TOKEN_LSS_THAN: + data->comparer = PROTOCOLTRACE_COMPARER_LESS_EQ; + break; + case PROTOCOLTRACE_TOKEN_GRT_THAN: + data->comparer = PROTOCOLTRACE_COMPARER_GREATER; + break; + case PROTOCOLTRACE_TOKEN_GRT_EQ: + data->comparer = PROTOCOLTRACE_COMPARER_GREATE_EQ; + break; + default: + goto fail; + } + + parser_token_process(token); + + if(token->last_token == PROTOCOLTRACE_TOKEN_NUMBER) + { + data->value_type = PROTOCOLTRACE_DATA_TYPE_INTEGER; + data->value.integer = atoi(token->last_symbol); + } + else if (token->last_token == PROTOCOLTRACE_TOKEN_SYMBOL) + { + data->value_type = PROTOCOLTRACE_DATA_TYPE_STRING; + strncpy(data->value.string, token->last_symbol, token->symbol_len); + data->value.string[token->symbol_len] = '\0'; + } + else + { + goto fail; + } + + parser_token_process(token); + + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << parser_statement_parse"); + return node; + fail: + if(node) + bintree_remove_node_recursive(node); + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << parser_statement_parse"); + return nullptr; +} + +ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::parser_token_parse(ProtocolTrace_Tree *tree, ProtocolTrace_Token_Data *token) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> parser_token_parse"); + DSLOG_DBG("DSWaylandProtocolTracePriv", "(parameter) string = %s, last token = %d, last symbol = %s", *token->string, token->last_token, token->last_symbol); + + ProtocolTrace_Tree_Node *node, *left = nullptr, *right = nullptr; + ProtocolTrace_Rule_Node *data; + + node = parser_statement_parse(tree,token); + + if(!node) + { + DSLOG_ERR("DSWaylandProtocolTracePriv", "PARSE statement error\n"); + goto fail; + } + + while(token->last_token == PROTOCOLTRACE_TOKEN_AND) + { + left = node; + node = nullptr; + + parser_token_process(token); + + right = parser_statement_parse(tree, token); + if(!right) + goto fail; + + node = bintree_create_node(tree); + // eina safety + + data = (ProtocolTrace_Rule_Node *) bintree_get_node_data(node); + data->node_type = PROTOCOLTRACE_NODE_TYPE_AND; + bintree_set_left_child(node, left); + bintree_set_right_child(node, right); + } + + if(token->last_token == PROTOCOLTRACE_TOKEN_OR) + { + left = node; + node = nullptr; + + parser_token_process(token); + + right = parser_token_parse(tree, token); + if(!right) + goto fail; + + node = bintree_create_node(tree); + //eina safety + + data = (ProtocolTrace_Rule_Node *) bintree_get_node_data(node); + data->node_type = PROTOCOLTRACE_NODE_TYPE_OR; + bintree_set_left_child(node, left); + bintree_set_right_child(node, right); + } + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << parser_token_parse"); + return node; + + fail: + DSLOG_DBG("DSWaylandProtocolTracePriv", "[fail] recursive remove node"); + if(left) + bintree_remove_node_recursive(left); + DSLOG_DBG("DSWaylandProtocolTracePriv", "return null"); + return nullptr; +} + +void DSWaylandProtocolTracePrivate::parser_token_process(ProtocolTrace_Token_Data *token) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> parser_token_process"); + do + { + token->last_symbol = *(token->string); + DSLOG_DBG("DSWaylandProtocolTracePriv", "last symbol = %c", token->last_symbol); + token->last_token = parser_next_token_get(token->string); + DSLOG_DBG("DSWaylandProtocolTracePriv", "last token = %d", token->last_token); + token->symbol_len = *(token->string) - token->last_symbol; + DSLOG_DBG("DSWaylandProtocolTracePriv", "last_symbol : %s , last_token : %d, symbol_len : %d", token->last_symbol, token->last_token, token->symbol_len); + } while (token->last_token == PROTOCOLTRACE_TOKEN_SPACE); + + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << parser_token_process"); +} + +void DSWaylandProtocolTracePrivate::protocol_arguments_merge(char *target, int target_size, int argc, const char **argv) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> protocol_arguments_merge"); + DSLOG_DBG("DSWaylandProtocolTracePriv", "(parameter) target = %s", target); + DSLOG_DBG("DSWaylandProtocolTracePriv", "(parameter) target size= %d", target_size); + + int i, len; + + for(i=0; i> protocol_cmd_get"); + char *p; + if(!path) return nullptr; + + p = strrchr(path, '/'); + + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << protocol_cmd_get"); + return (p)?p+1:path; +} + +void DSWaylandProtocolTracePrivate::rulechecker_destroy(ProtocolTrace_Rule_Checker *rc) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rulechecker_destroy"); + + int i; + for(i=rc->count-1; i>=0; i--) + rulechecker_rule_remove(rc,i); + + //free(rc); + delete rc; + + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << rulechecker_destroy"); +} + +ProtocolTrace_Rule_Checker *DSWaylandProtocolTracePrivate::rulechecker_init() +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rulechecker_init"); + + ProtocolTrace_Rule_Checker *rc = (ProtocolTrace_Rule_Checker *) calloc(1, sizeof(ProtocolTrace_Rule_Checker)); + if (!rc) + return nullptr; + + rc->count = 0; + + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << rulechecker_init"); + + return rc; +} + +int DSWaylandProtocolTracePrivate::rulechecker_int_compare(ProtocolTrace_Comparer comparer, int int2, int int1) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rulechecker_int_compare >> "); + + switch (comparer) + { + case PROTOCOLTRACE_COMPARER_EQUAL: + return int1 == int2; + case PROTOCOLTRACE_COMPARER_LESS: + return int1 < int2; + case PROTOCOLTRACE_COMPARER_GREATER: + return int1 > int2; + case PROTOCOLTRACE_COMPARER_LESS_EQ: + return int1 <= int2; + case PROTOCOLTRACE_COMPARER_GREATE_EQ: + return int1 >= int2; + case PROTOCOLTRACE_COMPARER_NOT_EQ: + return int1 != int2; + } + return 0; +} + +ProtocolTrace_Rule_Set_Result DSWaylandProtocolTracePrivate::rulechecker_rule_add(ProtocolTrace_Rule_Checker *rc, ProtocolTrace_Policy_Type policy, const char *rule_string) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rulechecker_rule_add"); + DSLOG_DBG("DSWaylandProtocolTracePriv", "rc->count = %d", rc->count); + + if(rc->count == MAX_RULE) + return PROTOCOLTRACE_RULE_SET_ERR_TOO_MANY_RULES; + + rc->rules[rc->count].tree = protocol_parser_rule_string_parse(rule_string); + if(!rc->rules[rc->count].tree) + { + DSLOG_DBG("DSWaylandProtocolTracePriv", "parse error"); + return PROTOCOLTRACE_RULE_SET_ERR_PARSE; + } + + rc->rules[rc->count].policy = policy; + rc->count++; + DSLOG_DBG("DSWaylandProtocolTracePriv", "rc->rules[rc->count].policy = %d", rc->rules[rc->count -1].policy); + DSLOG_DBG("DSWaylandProtocolTracePriv", "rc->count = %d", rc->count -1); + + return PROTOCOLTRACE_RULE_SET_OK; +} + +void DSWaylandProtocolTracePrivate::rulechecker_rule_print(ProtocolTrace_Rule_Checker *rc) +{ + char *reply; + int *len; + ProtocolTrace_Reply_Buffer buffer = {&reply, len}; + int i; + + DSLOG_INF("DSWaylandProtocolTracePriv"," --------------------------[ Protocol Filter Rules ]--------------------------\n"); + DSLOG_INF("DSWaylandProtocolTracePriv"," No Policy Rule\n"); + DSLOG_INF("DSWaylandProtocolTracePriv"," -----------------------------------------------------------------------------\n"); + + for(i =0; i < rc->count; i++) + { + DSLOG_INF("DSWaylandProtocolTracePriv"," %3d %10s \"", i, rc->rules[i].policy == PROTOCOLTRACE_TYPE_ALLOW ? "ALLOW" : "DENY"); + bintree_inorder_traverse(rc->rules[i].tree, rule_print_func, (void*) & buffer); + DSLOG_INF("DSWaylandProtocolTracePriv","\"\n"); + + } +} + +ProtocolTrace_Rule_Set_Result DSWaylandProtocolTracePrivate::rulechecker_rule_remove(ProtocolTrace_Rule_Checker *rc, int index) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rulechecker_rule_remove"); + + if(index <0 || index >= rc->count) + return PROTOCOLTRACE_RULE_SET_ERR_NO_RULE; + + bintree_destroy_tree(rc->rules[index].tree); + rc->count--; + if(index!=rc->count) + memmove(&rc->rules[index], &rc->rules[index+1], sizeof(ProtocolTrace_Rule)*(rc->count - index)); + + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << rulechecker_rule_remove"); + + return PROTOCOLTRACE_RULE_SET_OK; +} + +int DSWaylandProtocolTracePrivate::rulechecker_rule_validate(ProtocolTrace_Rule_Checker *rc, int type, int target_id, const char *name, int pid, char *cmd) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rulechecker_rule_validate"); + + ProtocolTrace_Validate_Args args = {type, target_id, name, pid, cmd}; + ProtocolTrace_Tree_Node *node; + ProtocolTrace_Rule_Node *data; + ProtocolTrace_Policy_Type default_policy = PROTOCOLTRACE_TYPE_DENY; + int i; + + for(i=rc->count-1; i>=0; i--) + { + bintree_postorder_traverse(rc->rules[i].tree, rule_validate_func, &args); + node = (ProtocolTrace_Tree_Node *) bintree_get_head(rc->rules[i].tree); + data = (ProtocolTrace_Rule_Node *) bintree_get_node_data(node); + + if(data->result == PROTOCOLTRACE_RESULT_TRUE) + { + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << rulechecker_rule_validate"); + return rc->rules[i].policy == PROTOCOLTRACE_TYPE_ALLOW; + } + } + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << rulechecker_rule_validate"); + return default_policy == PROTOCOLTRACE_TYPE_ALLOW; +} + +int DSWaylandProtocolTracePrivate::rulechecker_string_compare(ProtocolTrace_Comparer comparer, char *str2, char *str1) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rulechecker_string_compare >> "); + + int result = strcasecmp(str2, str1); + + switch (comparer) + { + case PROTOCOLTRACE_COMPARER_EQUAL: + return result == 0; + case PROTOCOLTRACE_COMPARER_LESS: + return result < 0; + case PROTOCOLTRACE_COMPARER_GREATER: + return result > 0; + case PROTOCOLTRACE_COMPARER_LESS_EQ: + return result <= 0; + case PROTOCOLTRACE_COMPARER_GREATE_EQ: + return result >= 0; + case PROTOCOLTRACE_COMPARER_NOT_EQ: + return result != 0; + } + return 0; +} + +const char * DSWaylandProtocolTracePrivate::rulechecker_usage_print() +{ + return + "##########################################################\n" + "### Enlightenment Protocol Log filtering. ###\n" + "##########################################################\n" + "\n" + "-----------------------------------------------------------------\n" + "How to read enlightenment_info protocol messages :\n" + "[timestamp] Server --> Client [PID: [pid]] interface@id.message(arguments..) cmd: CMD\n" + " ex)\n" + "[1476930.145] Server --> Client [PID: 103] wl_touch@10.down(758, 6769315, wl_surface@23, 0, 408.000, 831.000) cmd: /usr/bin/launchpad-loader\n" + " ==> type = event && pid = 103 && cmd = launchpad-loader && iface = wl_touch && msg = up\n" + "[4234234.123] Server <-- Client [PID: 123] wl_seat@32.get_touch(new id wl_touch@22) cmd: /usr/bin/launchpad-loader\n" + " ==> type = request && pid = 123 && cmd = launchpad-loader && iface = wl_seat && msg = get_touch\n" + "-----------------------------------------------------------------\n" + "Usage : enlightenment_info -protocol_rule add [POLICY] [RULE]\n" + " enlightenment_info -protocol_rule remove [INDEX]\n" + " enlightenment_info -protocol_rule file [RULE_FILE]\n" + " enlightenment_info -protocol_rule print\n" + " enlightenment_info -protocol_rule help\n" + " [POLICY] : allow / deny \n" + " [RULE] : C Language-style boolean expression syntax. [VARIABLE] [COMPAROTOR] [VALUE]\n" + " [VARIABLE] : type / iface / msg / cmd(command) / pid\n" + " [COMPARATOR] : & / && / and / | / || / or / = / == / != / > / >= / < / <=\n" + " [VALUE] : string / number \n" + " ex)\n" + " enlightenment_info -protocol_rule add allow \"(type=request) && (iface == wl_pointer and (msg = down or msg = up))\"\n" + " enlightenment_info -protocol_rule add deny cmd!= launch-loader\n" + " enlightenment_info -protocol_rule remove all\n" + " enlightenment_info -protocol_rule remove 3\n" + "\n"; +} + +int DSWaylandProtocolTracePrivate::rule_print_func(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rule_print_func"); + ProtocolTrace_Reply_Buffer *buffer = (ProtocolTrace_Reply_Buffer *)arg; + char *reply = *buffer->reply; + int *len = buffer->len; + char *operators[] = {"==", "<", ">", "<=", ">=", "!=" }; + ProtocolTrace_Rule_Node *data; + + data = (ProtocolTrace_Rule_Node *)bintree_get_node_data(node); + + if(data->node_type == PROTOCOLTRACE_NODE_TYPE_ALL) + DSLOG_INF("DSWaylandProtocolTracePriv", "------------------------------------------------- ALL"); + else if(data->node_type == PROTOCOLTRACE_NODE_TYPE_AND) + DSLOG_INF("DSWaylandProtocolTracePriv", "------------------------------------------------- AND"); + else if(data->node_type == PROTOCOLTRACE_NODE_TYPE_OR) + DSLOG_INF("DSWaylandProtocolTracePriv", "------------------------------------------------- OR"); + else // data->node_type == PROTOCOLTRACE_NODE_TYPE_DATA + { + if(node == bintree_get_left_child(parent)) + DSLOG_INF("DSWaylandProtocolTracePriv", "------------------------------------------------- ("); + DSLOG_INF("DSWaylandProtocolTracePriv", "------------------------------------------------- %s %s ", data->variable_name, operators[data->comparer]); + + if(data->value_type == PROTOCOLTRACE_DATA_TYPE_INTEGER) + DSLOG_INF("DSWaylandProtocolTracePriv", "------------------------------------------------- %d", data->value.integer); + else + DSLOG_INF("DSWaylandProtocolTracePriv", "------------------------------------------------- %s", data->value.string); + + if(node == bintree_get_right_child(parent)) + DSLOG_INF("DSWaylandProtocolTracePriv", "------------------------------------------------- )"); + } + + *buffer->reply = reply; + DSLOG_DBG("DSWaylandProtocolTracePriv", "buffer->reply = %s", reply); + + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << rule_print_func"); + return 0; +} + +int DSWaylandProtocolTracePrivate::rule_validate_func(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg) +{ + DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rule_validate_func "); + + ProtocolTrace_Validate_Args *args = (ProtocolTrace_Validate_Args *)arg; + ProtocolTrace_Tree_Node *left, *right; + ProtocolTrace_Rule_Node *data, *left_data =nullptr, *right_data = nullptr; + + data = (ProtocolTrace_Rule_Node *)bintree_get_node_data(node); + data->result = PROTOCOLTRACE_RESULT_UNKNOWN; + + if(data->node_type == PROTOCOLTRACE_NODE_TYPE_AND || data->node_type == PROTOCOLTRACE_NODE_TYPE_OR) + { + left = bintree_get_left_child(node); + right = bintree_get_right_child(node); + if(!left || !right) + { + DSLOG_ERR("DSWaylandProtocolTracePriv", "Node error"); + return -1; + } + + left_data = (ProtocolTrace_Rule_Node *)bintree_get_node_data(left); + right_data = (ProtocolTrace_Rule_Node *)bintree_get_node_data(right); + } + + if(data->node_type == PROTOCOLTRACE_NODE_TYPE_ALL) + { + data->result = PROTOCOLTRACE_RESULT_TRUE; + } + else if(data->node_type == PROTOCOLTRACE_NODE_TYPE_DATA) + { + char iface[64]; + char *msg = nullptr; + + if(args->name) + msg = ":";//index(args->name, ":"); + if(msg) + { + int min = MIN(sizeof(iface)-1, msg-args->name); + strncpy(iface, args->name, min); + iface[min] = '\0'; + msg++; + } + if(!strcasecmp(data->variable_name, "TYPE")) + { + char *type_string; + if(args->type == 0) + type_string = "REQUEST"; + else if(args->type == 1) + type_string = "EVENT"; + else + { + DSLOG_ERR("DSWaylandProtocolTracePriv", "Invalid type %d", args->type); + return -1; + } + + if(rulechecker_string_compare(data->comparer, data->value.string, type_string)) + data->result = PROTOCOLTRACE_RESULT_TRUE; + else + data->result = PROTOCOLTRACE_RESULT_FALSE; + } + else if(!strcasecmp(data->variable_name, "IFACE")) + { + if(msg && rulechecker_string_compare(data->comparer, data->value.string, iface)) + data->result = PROTOCOLTRACE_RESULT_TRUE; + else + data->result = PROTOCOLTRACE_RESULT_FALSE; + } + else if(!strcasecmp(data->variable_name, "MSG")) + { + if(msg && rulechecker_string_compare(data->comparer, data->value.string, msg)) + data->result = PROTOCOLTRACE_RESULT_TRUE; + else + data->result = PROTOCOLTRACE_RESULT_FALSE; + } + else if(!strcasecmp(data->variable_name, "PID")) + { + if(rulechecker_int_compare(data->comparer, data->value.integer, args->pid)) + data->result = PROTOCOLTRACE_RESULT_TRUE; + else + data->result = PROTOCOLTRACE_RESULT_FALSE; + } + else if(!strcasecmp(data->variable_name, "CMD") || !strcasecmp(data->variable_name, "COMMAND")) + { + if(msg && rulechecker_string_compare(data->comparer, data->value.string, args->cmd)) + data->result = PROTOCOLTRACE_RESULT_TRUE; + else + data->result = PROTOCOLTRACE_RESULT_FALSE; + } + } + else if(data->node_type == PROTOCOLTRACE_NODE_TYPE_AND) + { + if(left_data->result == PROTOCOLTRACE_RESULT_TRUE && right_data->result == PROTOCOLTRACE_RESULT_TRUE) + data->result = PROTOCOLTRACE_RESULT_TRUE; + else + data->result = PROTOCOLTRACE_RESULT_FALSE; + } + else if(data->node_type == PROTOCOLTRACE_NODE_TYPE_OR) + { + if(left_data->result == PROTOCOLTRACE_RESULT_TRUE || right_data->result == PROTOCOLTRACE_RESULT_TRUE) + data->result = PROTOCOLTRACE_RESULT_TRUE; + else + data->result = PROTOCOLTRACE_RESULT_FALSE; + } + else + { + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << rule_validate_func "); + return -1; + } + + DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << rule_validate_func "); + return 0; } } // namespace display_server \ No newline at end of file diff --git a/src/DSWaylandServer/DSWaylandProtocolTrace.h b/src/DSWaylandServer/DSWaylandProtocolTrace.h index b9526df..70a5d6c 100644 --- a/src/DSWaylandServer/DSWaylandProtocolTrace.h +++ b/src/DSWaylandServer/DSWaylandProtocolTrace.h @@ -26,6 +26,7 @@ #include #include +#include "DSWaylandCompositor.h" namespace display_server { diff --git a/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h b/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h index d43ed9d..8c22087 100644 --- a/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h +++ b/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h @@ -25,9 +25,199 @@ #define __DS_WAYLAND_PROTOCOL_TRACE_PRIVATE_H__ #include "DSWaylandProtocolTrace.h" +//#include "DSWaylandProtocolTraceStruct.h" +#include +#include +#include +#include + +#define PATH_MAX 255 //tmp 255 + +#ifndef MAX +#define MAX(x, y) (((x) > (y)) ? (x) : (y)) +#endif + +#ifndef MIN +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) +#endif + +#define BUF_SNPRINTF(fmt, ARG...) do { \ + str_l = snprintf(str_buff, str_r, fmt, ##ARG); \ + str_buff += str_l; \ + str_r -= str_l; \ +} while(0) + + +/* +#ifndef REPLY + #define REPLY(fmt, ARG...) \ + do { \ + if (reply && len && *len > 0) \ + { \ + int s = snprintf(reply, *len, fmt, ##ARG); \ + reply += s; \ + *len -= s; \ + } \ + } while (0) +#endif +*/ +#define MAX_RULE 64 +#define STRING_MAX 64 namespace display_server { +typedef struct _ProtocolTrace_Tree_Node ProtocolTrace_Tree_Node; +typedef struct _ProtocolTrace_Tree ProtocolTrace_Tree; +typedef struct _ProtocolTrace_Token_Data ProtocolTrace_Token_Data; +typedef struct _ProtocolTrace_Rule_Node ProtocolTrace_Rule_Node; +typedef struct _ProtocolTrace_Rule ProtocolTrace_Rule; +typedef struct _ProtocolTrace_Rule_Checker ProtocolTrace_Rule_Checker; +typedef struct _ProtocolTrace_Protocol_Log ProtocolTrace_Protocol_Log; + +typedef int (*ProtocolTrace_Tree_Traverse_Cb) (ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg); + +struct _ProtocolTrace_Tree_Node +{ + ProtocolTrace_Tree_Node *left; + ProtocolTrace_Tree_Node *right; +}; + +struct _ProtocolTrace_Tree +{ + int size; + ProtocolTrace_Tree_Node *head; +}; + +typedef enum +{ + PROTOCOLTRACE_TOKEN_UNKNOWN = 0, + PROTOCOLTRACE_TOKEN_L_BR =1, + PROTOCOLTRACE_TOKEN_R_BR =2, + PROTOCOLTRACE_TOKEN_NOT_EQ=3, + PROTOCOLTRACE_TOKEN_EQUAL=4, + PROTOCOLTRACE_TOKEN_LSS_THAN=5, + PROTOCOLTRACE_TOKEN_LSS_EQ =6, + PROTOCOLTRACE_TOKEN_GRT_THAN=7, + PROTOCOLTRACE_TOKEN_GRT_EQ =8, + PROTOCOLTRACE_TOKEN_AND=9, + PROTOCOLTRACE_TOKEN_OR=10, + PROTOCOLTRACE_TOKEN_SPACE=11, + PROTOCOLTRACE_TOKEN_SYMBOL=12, + PROTOCOLTRACE_TOKEN_NUMBER=13, + PROTOCOLTRACE_TOKEN_EOS=14, +} ProtocolTrace_Token; + +struct _ProtocolTrace_Token_Data +{ + const char **string; + ProtocolTrace_Token last_token; + const char *last_symbol; + int symbol_len; +}; +typedef enum +{ + PROTOCOLTRACE_NODE_TYPE_NONE, + PROTOCOLTRACE_NODE_TYPE_AND, + PROTOCOLTRACE_NODE_TYPE_OR, + PROTOCOLTRACE_NODE_TYPE_DATA, + PROTOCOLTRACE_NODE_TYPE_ALL +} ProtocolTrace_Node_Type; + +typedef enum +{ + PROTOCOLTRACE_COMPARER_EQUAL, + PROTOCOLTRACE_COMPARER_LESS, + PROTOCOLTRACE_COMPARER_GREATER, + PROTOCOLTRACE_COMPARER_LESS_EQ, + PROTOCOLTRACE_COMPARER_GREATE_EQ, + PROTOCOLTRACE_COMPARER_NOT_EQ +} ProtocolTrace_Comparer; + +typedef enum +{ + PROTOCOLTRACE_DATA_TYPE_INTEGER, + PROTOCOLTRACE_DATA_TYPE_STRING +} ProtocolTrace_Data_Type; + +typedef enum +{ + PROTOCOLTRACE_RESULT_UNKNOWN, + PROTOCOLTRACE_RESULT_TRUE, + PROTOCOLTRACE_RESULT_FALSE +} ProtocolTrace_Result_Type; + +struct _ProtocolTrace_Rule_Node +{ + ProtocolTrace_Node_Type node_type; + char variable_name[STRING_MAX]; + ProtocolTrace_Comparer comparer; + ProtocolTrace_Data_Type value_type; + + union + { + char string[STRING_MAX]; + int integer; + }value; + + ProtocolTrace_Result_Type result; +}; + +typedef enum +{ + PROTOCOLTRACE_POLICY_TYPE_UNDEFINED, + PROTOCOLTRACE_TYPE_ALLOW, + PROTOCOLTRACE_TYPE_DENY +} ProtocolTrace_Policy_Type; + +struct _ProtocolTrace_Rule +{ + ProtocolTrace_Policy_Type policy; + ProtocolTrace_Tree *tree; +}; + +struct _ProtocolTrace_Rule_Checker +{ + ProtocolTrace_Rule rules[MAX_RULE]; + int count; +}; +typedef enum +{ + PROTOCOLTRACE_RULE_SET_OK, + PROTOCOLTRACE_RULE_SET_ERR_TOO_MANY_RULES, + PROTOCOLTRACE_RULE_SET_ERR_PARSE, + PROTOCOLTRACE_RULE_SET_ERR_NO_RULE + } ProtocolTrace_Rule_Set_Result; +typedef enum{ + PROTOCOL_TYPE_REQUEST, + PROTOCOL_TYPE_EVENT +} ProtocolTrace_Protocol_Type; +struct _ProtocolTrace_Protocol_Log +{ + ProtocolTrace_Protocol_Type type; + int client_pid; + int target_id; + char name[PATH_MAX +1]; + char cmd[PATH_MAX +1]; +}; +struct argument_details { + char type; + int nullable; +}; + +typedef struct +{ + int type; + int target_id; + const char *name; + int pid; + char *cmd; +} ProtocolTrace_Validate_Args; + +typedef struct +{ + char **reply; + int *len; +} ProtocolTrace_Reply_Buffer; class DSWaylandProtocolTracePrivate : public DSObjectPrivate { @@ -40,11 +230,59 @@ public: protected: - void protocol_rule_init(char *rule_path); - void protocol_trace_init(char *trace_path); - void protocol_rule_set(void); - void protocol_rule_file_set(void); + bool protocol_rule_init(char *rule_path); + bool protocol_trace_init(char *trace_path); + + bool protocol_rule_set(const int argc, const char **argv); + bool protocol_rule_file_set(const char *filename); + static bool protocol_rule_validate(ProtocolTrace_Protocol_Log *log); + + void protocol_trace_set(void); + void protocol_trace_unset(void); + +private: + DSWaylandCompositor *__wlCompositor; + char *trace_env_path = nullptr; + + static void wl_protocol_cb_client_destroy(struct wl_listener *listener, void *data); + static void protocol_client_destroy_listener_reg(struct wl_client *client); + static void protocol_trace_func(void *user_data, enum wl_protocol_logger_type direction, const struct wl_protocol_logger_message *message); + + ProtocolTrace_Tree_Node *bintree_create_node(ProtocolTrace_Tree *tree); + ProtocolTrace_Tree *bintree_create_tree(int size); + void bintree_destroy_tree(ProtocolTrace_Tree *tree); + static ProtocolTrace_Tree_Node *bintree_get_head(ProtocolTrace_Tree *tree); + static ProtocolTrace_Tree_Node *bintree_get_left_child(ProtocolTrace_Tree_Node *node); + static void * bintree_get_node_data(ProtocolTrace_Tree_Node *node); + static ProtocolTrace_Tree_Node *bintree_get_right_child(ProtocolTrace_Tree_Node *node); + void bintree_inorder_traverse(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Traverse_Cb func, void *arg); + int bintree_inorder_traverse_recursive(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, ProtocolTrace_Tree_Traverse_Cb func, void *arg); + static void bintree_postorder_traverse(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Traverse_Cb func, void *arg); + static int bintree_postorder_traverse_recursive(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, ProtocolTrace_Tree_Traverse_Cb func, void *arg); + void bintree_remove_node(ProtocolTrace_Tree_Node *node); + void bintree_remove_node_recursive(ProtocolTrace_Tree_Node *node); + void bintree_set_head(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *head); + void bintree_set_left_child(ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *child); + void bintree_set_right_child(ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *child); + ProtocolTrace_Token parser_next_token_get(const char **string); + ProtocolTrace_Tree *protocol_parser_rule_string_parse(const char *string); + ProtocolTrace_Tree_Node *parser_statement_parse(ProtocolTrace_Tree *tree, ProtocolTrace_Token_Data *token); + ProtocolTrace_Tree_Node *parser_token_parse(ProtocolTrace_Tree *tree, ProtocolTrace_Token_Data *token); + void parser_token_process(ProtocolTrace_Token_Data *token); + static void protocol_arguments_merge(char *target, int target_size, int argc, const char **argv); + static char * protocol_cmd_get(char *path); + void rulechecker_destroy(ProtocolTrace_Rule_Checker *rc); + ProtocolTrace_Rule_Checker *rulechecker_init(); + static int rulechecker_int_compare(ProtocolTrace_Comparer comparer, int int2, int int1); + ProtocolTrace_Rule_Set_Result rulechecker_rule_add(_ProtocolTrace_Rule_Checker *rc, ProtocolTrace_Policy_Type policy, const char *rule_string); + void rulechecker_rule_print(ProtocolTrace_Rule_Checker *rc); + ProtocolTrace_Rule_Set_Result rulechecker_rule_remove(ProtocolTrace_Rule_Checker *rc, int index); + static int rulechecker_rule_validate(ProtocolTrace_Rule_Checker *rc, int type, int target_id, const char *name, int pid, char *cmd); + static int rulechecker_string_compare(ProtocolTrace_Comparer comparer, char *str2, char *str1); + const char * rulechecker_usage_print(); + static int rule_print_func(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg); + static int rule_validate_func(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg); }; } -- 2.7.4 From c755d4d90af069ab069c03a9e537e522ec8c6144 Mon Sep 17 00:00:00 2001 From: dyamy-lee Date: Thu, 20 Aug 2020 15:08:23 +0900 Subject: [PATCH 07/16] add func of update rule and add test code Change-Id: Ia7891fb079711b6198b786604e4708fa3c900fe5 --- src/DSWaylandServer/DSWaylandProtocolTrace.cpp | 16 ++++++ src/DSWaylandServer/DSWaylandProtocolTrace.h | 2 +- tests/DSWaylandProtocolTrace-test.cpp | 71 +++++++++++++++++++++++++- 3 files changed, 86 insertions(+), 3 deletions(-) diff --git a/src/DSWaylandServer/DSWaylandProtocolTrace.cpp b/src/DSWaylandServer/DSWaylandProtocolTrace.cpp index fe89016..869bcb7 100644 --- a/src/DSWaylandServer/DSWaylandProtocolTrace.cpp +++ b/src/DSWaylandServer/DSWaylandProtocolTrace.cpp @@ -204,6 +204,18 @@ int DSWaylandProtocolTrace::enableProtocolTrace(bool state) return -1; } + +bool DSWaylandProtocolTrace::updateProtocolRule(const int argc, const char **argv) +{ + DS_GET_PRIV(DSWaylandProtocolTrace); + DSLOG_DBG("DSWaylandProtocolTrace", "argc = %d, argv[0] = %s, argv[1] = %s", argc, argv[0], argv[1]); + + bool ret = false; + ret = priv->protocol_rule_set(argc, argv); + + return ret; +} + DSWaylandProtocolTracePrivate::DSWaylandProtocolTracePrivate(DSWaylandProtocolTrace *p_ptr) : DSObjectPrivate(p_ptr), __p_ptr(p_ptr) { @@ -265,6 +277,7 @@ bool DSWaylandProtocolTracePrivate::protocol_trace_init(char *trace_path) bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char **argv) { DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> protocol_rule_set"); + DSLOG_DBG("DSWaylandProtocolTracePriv", "(parameter) argc = %d, argv[0] = %s", argc, argv[0]); const char * command; if(argc == 0) @@ -408,6 +421,8 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char } } rulechecker_rule_print(rc); + + return true; } else if(!strcasecmp(command, "file")) { @@ -532,6 +547,7 @@ void DSWaylandProtocolTracePrivate::protocol_trace_set(void) display = __wlCompositor->display(); DSLOG_DBG("DSWaylandProtocolTracePriv","get display "); + //check working ds_wl_protocol_logger = wl_display_add_protocol_logger(display, protocol_trace_func, nullptr); DSLOG_DBG("DSWaylandProtocolTracePriv","OUT << protocol trace set"); } diff --git a/src/DSWaylandServer/DSWaylandProtocolTrace.h b/src/DSWaylandServer/DSWaylandProtocolTrace.h index 70a5d6c..b53e999 100644 --- a/src/DSWaylandServer/DSWaylandProtocolTrace.h +++ b/src/DSWaylandServer/DSWaylandProtocolTrace.h @@ -45,7 +45,7 @@ public: bool init(void); int enableProtocolTrace(bool state); - //int registerProtocolRule(void); + bool updateProtocolRule(const int argc, const char **argv); private: static std::mutex __mutex; diff --git a/tests/DSWaylandProtocolTrace-test.cpp b/tests/DSWaylandProtocolTrace-test.cpp index e02cf3e..63d0e67 100644 --- a/tests/DSWaylandProtocolTrace-test.cpp +++ b/tests/DSWaylandProtocolTrace-test.cpp @@ -45,15 +45,82 @@ TEST_F(DSWaylandProtocolTraceTest, NewDSWaylandProtocolTrace) DSWaylandProtocolTrace::releaseInstance(); } -TEST_F(DSWaylandProtocolTraceTest, BasicMethods) +TEST_F(DSWaylandProtocolTraceTest, DSWaylandProtocolTraceInit) { DSWaylandProtocolTrace *pTrace = DSWaylandProtocolTrace::getInstance(); - bool trace_state = false; //disable if(pTrace) { EXPECT_TRUE(pTrace->init() == true); + DSWaylandProtocolTrace::releaseInstance(); + } +} + +TEST_F(DSWaylandProtocolTraceTest, DSWaylandProtocolTraceUpdateRule) +{ + DSWaylandProtocolTrace *pTrace = DSWaylandProtocolTrace::getInstance(); + + if(pTrace) + { + pTrace->init(); + + int argc = 3; + char *argv[3]; + argv[0] = "add"; + argv[1] = "ALLOW"; + argv[2] = "all"; + EXPECT_TRUE(pTrace->updateProtocolRule(argc, (const char**)&(argv[0])) == true); + + argc = 2; + argv[0] = "remove"; + argv[1] = "all"; + argv[2] = nullptr; + EXPECT_TRUE(pTrace->updateProtocolRule(argc, (const char**)&(argv[0])) == true); + + argc = 1; + argv[0] = "print"; + argv[1] = nullptr; + argv[2] = nullptr; + EXPECT_TRUE(pTrace->updateProtocolRule(argc, (const char**)&(argv[0])) == true); + + argc = 1; + argv[0] = "help"; + argv[1] = nullptr; + argv[2] = nullptr; + EXPECT_TRUE(pTrace->updateProtocolRule(argc, (const char**)&(argv[0])) == true); + + argc = 1; + argv[0] = "command"; + argv[1] = nullptr; + argv[2] = nullptr; + EXPECT_TRUE(pTrace->updateProtocolRule(argc, (const char**)&(argv[0])) == true); + DSWaylandProtocolTrace::releaseInstance(); + } + +} + +TEST_F(DSWaylandProtocolTraceTest, DSWaylandProtocolTraceEnableTraceFalse) +{ + DSWaylandProtocolTrace *pTrace = DSWaylandProtocolTrace::getInstance(); + bool trace_state = false; //disable + + if(pTrace) + { + pTrace->init(); EXPECT_TRUE(pTrace->enableProtocolTrace(trace_state) == 0); DSWaylandProtocolTrace::releaseInstance(); } +} + +TEST_F(DSWaylandProtocolTraceTest, DSWaylandProtocolTraceEnableTraceTrue) +{ + DSWaylandProtocolTrace *pTrace = DSWaylandProtocolTrace::getInstance(); + bool trace_state = true; + + if(pTrace) + { + pTrace->init(); + EXPECT_TRUE(pTrace->enableProtocolTrace(trace_state) == 1); + DSWaylandProtocolTrace::releaseInstance(); + } } \ No newline at end of file -- 2.7.4 From 80211ebd03930281a16d45a2966f82dd72541f11 Mon Sep 17 00:00:00 2001 From: dyamy-lee Date: Fri, 21 Aug 2020 15:21:39 +0900 Subject: [PATCH 08/16] remove some logs which make a error and not useful Change-Id: I05920622c295cc5b7022a1cd2730111f07448870 --- src/DSWaylandServer/DSWaylandProtocolTrace.cpp | 172 ++----------------------- 1 file changed, 11 insertions(+), 161 deletions(-) diff --git a/src/DSWaylandServer/DSWaylandProtocolTrace.cpp b/src/DSWaylandServer/DSWaylandProtocolTrace.cpp index 869bcb7..97eaad0 100644 --- a/src/DSWaylandServer/DSWaylandProtocolTrace.cpp +++ b/src/DSWaylandServer/DSWaylandProtocolTrace.cpp @@ -100,7 +100,7 @@ DSWaylandProtocolTrace::DSWaylandProtocolTrace(DSObject *parent) DSWaylandProtocolTrace::~DSWaylandProtocolTrace() { - + DSWaylandCompositor::releaseInstance(); } DSWaylandProtocolTrace *DSWaylandProtocolTrace::getInstance() @@ -144,14 +144,14 @@ bool DSWaylandProtocolTrace::init(void) // set rule file path env_path = getenv("E_INFO_RULE_FILE"); - DSLOG_DBG("DSWaylandProtocolTrace", "========================== rule file path = %s", env_path); + DSLOG_DBG("DSWaylandProtocolTrace", "==================================================== rule file path = %s", env_path); ret = priv->protocol_rule_init(env_path); DSLOG_DBG("DSWaylandProtocolTrace", "result of protocol rule init = %d", ret); if(env_path) { + //TODO: free env_path DSLOG_DBG("DSWaylandProtocolTrace", "delete rule file path = %s", env_path); - //delete env_path; //free(env_path); env_path = nullptr; DSLOG_DBG("DSWaylandProtocolTrace", "delete rule file path done."); @@ -159,15 +159,15 @@ bool DSWaylandProtocolTrace::init(void) if(!ret) return ret; // set trace file path - DSLOG_DBG("DSWaylandProtocolTrace", "===================================================="); + DSLOG_DBG("DSWaylandProtocolTrace", "========================================================================================================"); env_path = getenv("E_INFO_TRACE_FILE"); - DSLOG_DBG("DSWaylandProtocolTrace", "========================== trace file path = %s", env_path); + DSLOG_DBG("DSWaylandProtocolTrace", "==================================================== trace file path = %s", env_path); ret = priv->protocol_trace_init(env_path); DSLOG_DBG("DSWaylandProtocolTrace", "result of protocol trace init = %d", ret); if(env_path) { + //TODO: free env_path DSLOG_DBG("DSWaylandProtocolTrace", "delete trace file path = %s", env_path); - //delete env_path; //free(env_path); env_path = nullptr; DSLOG_DBG("DSWaylandProtocolTrace", "delete trace file path done."); @@ -255,7 +255,7 @@ bool DSWaylandProtocolTracePrivate::protocol_trace_init(char *trace_path) DSLOG_DBG("DSWaylandProtocolTracePriv", "saved trace path = %s", trace_env_path); //enable - protocol_trace_set(); + protocol_trace_unset(); DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << protocol_trace_init"); /* log_fp_ptrace = fopen(trace_path, "a"); @@ -303,7 +303,6 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char //REPLY("Error : Too few arguments."); return false; } - DSLOG_DBG("DSWaylandProtocolTracePriv", "ADD :: go on"); if(!strcasecmp(policy, "ALLOW")) policy_type = PROTOCOLTRACE_TYPE_ALLOW; @@ -315,18 +314,14 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char //REPLY; return false; } - DSLOG_DBG("DSWaylandProtocolTracePriv", "ADD :: policy_type = %d", policy_type); // protocol arguments merge protocol_arguments_merge(merge, sizeof(merge), argc -2, &(argv[2])); - DSLOG_DBG("DSWaylandProtocolTracePriv", "ADD :: merge = %s", merge); size_rule = sizeof(rule) -1; - DSLOG_DBG("DSWaylandProtocolTracePriv", "ADD :: size_rule = %d", size_rule); for(i=0; isize_rule) return false; } DSLOG_DBG("DSWaylandProtocolTracePriv", "ADD :: rule = %s", rule); - DSLOG_DBG("DSWaylandProtocolTracePriv", "ADD :: rulechecker_rule_add (before) -> rc %d",rc->count); result = rulechecker_rule_add(rc, policy_type, rule); - DSLOG_DBG("DSWaylandProtocolTracePriv", "ADD :: rulechecker_rule_add (after) -> rc %d",rc->count); if(result == PROTOCOLTRACE_RULE_SET_ERR_TOO_MANY_RULES) { @@ -395,7 +387,6 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char if(!strcasecmp(remove_idx, "all")) { DSLOG_DBG("DSWaylandProtocolTracePriv", "REMOVE :: all"); - DSLOG_DBG("DSWaylandProtocolTracePriv", "REMOVE :: (before destroy) rc = %d", rc->count); rulechecker_destroy(rc); rc = rulechecker_init(); if(!rc) @@ -403,7 +394,6 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char DSLOG_ERR("DSWaylandProtocolTracePriv", "Error: rules not removed"); return false; } - DSLOG_DBG("DSWaylandProtocolTracePriv", "REMOVE :: (after destroy) rc = %d", rc->count); DSLOG_INF("DSWaylandProtocolTracePriv", "Every rules were successfully removed"); } else @@ -411,13 +401,10 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char int index = atoi(remove_idx); DSLOG_DBG("DSWaylandProtocolTracePriv", "REMOVE :: remove idx = %d", index); - DSLOG_DBG("DSWaylandProtocolTracePriv", "REMOVE :: (before rulechecker_rule_remove) rc = %d", rc->count); if(isdigit(*remove_idx) && rulechecker_rule_remove(rc, index) == 0) DSLOG_INF("DSWaylandProtocolTracePriv", "The rule [%d] was successfully removed.", index); else DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : No such rule [%s]", remove_idx); - - DSLOG_DBG("DSWaylandProtocolTracePriv", "REMOVE :: (after rulechecker_rule_remove) rc = %d", rc->count); } } rulechecker_rule_print(rc); @@ -514,7 +501,6 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_file_set(const char *filename) bool DSWaylandProtocolTracePrivate::protocol_rule_validate(ProtocolTrace_Protocol_Log *log) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> protocol_rule_validate << "); char *cmd = ""; if(!rc) @@ -565,8 +551,6 @@ void DSWaylandProtocolTracePrivate::protocol_trace_unset(void) void DSWaylandProtocolTracePrivate::wl_protocol_cb_client_destroy(struct wl_listener *listener, void *data) { - DSLOG_DBG("DSWaylandProtocolTracePriv","IN >> wl_protocol_cb_client_destroy"); - struct wl_client *wc = (struct wl_client *)data; struct timespec tp; unsigned int time; @@ -596,33 +580,26 @@ void DSWaylandProtocolTracePrivate::wl_protocol_cb_client_destroy(struct wl_list //free(listener); delete listener; listener = nullptr; - - DSLOG_DBG("DSWaylandProtocolTracePriv","OUT << wl_protocol_cb_client_destroy"); - } void DSWaylandProtocolTracePrivate::protocol_client_destroy_listener_reg(struct wl_client *client) { - DSLOG_DBG("DSWaylandProtocolTracePriv","IN >> protocol_client_destroy_listener_reg"); - struct wl_listener *destroy_listener; destroy_listener = wl_client_get_destroy_listener(client, wl_protocol_cb_client_destroy); - if(destroy_listener) return; + if(destroy_listener) { + return; + } destroy_listener = (struct wl_listener *)calloc(1, sizeof(wl_listener)); //EINA_SAFETY_ON_NULL_RETURN(destroy_listener); destroy_listener->notify = wl_protocol_cb_client_destroy; wl_client_add_destroy_listener(client, destroy_listener); - - DSLOG_DBG("DSWaylandProtocolTracePriv","OUT << protocol_client_destroy_listener_reg"); } void DSWaylandProtocolTracePrivate::protocol_trace_func(void *user_data, enum wl_protocol_logger_type direction, const struct wl_protocol_logger_message *message) { - DSLOG_DBG("DSWaylandProtocolTracePriv","IN >> protocol_trace_func"); - int i; struct argument_details arg; struct wl_client *wc = wl_resource_get_client(message->resource); @@ -639,25 +616,19 @@ void DSWaylandProtocolTracePrivate::protocol_trace_func(void *user_data, enum wl if(wc) { - DSLOG_DBG("DSWaylandProtocolTracePriv","has wl_client"); protocol_client_destroy_listener_reg(wc); wl_client_get_credentials(wc, &client_pid, nullptr, nullptr); } - DSLOG_DBG("DSWaylandProtocolTracePriv","go on"); - clock_gettime(CLOCK_MONOTONIC, &tp); time = (tp.tv_sec * 1000000L) + (tp.tv_nsec / 1000); ProtocolTrace_Protocol_Log elog = {PROTOCOL_TYPE_REQUEST,}; - DSLOG_DBG("DSWaylandProtocolTracePriv", "before get info protocol log => type: %s, client_pit: %d, target_id: %d, name: %s, cmd: %s", elog.type, elog.client_pid, elog.target_id, elog.name, elog.cmd); elog.type = (direction == WL_PROTOCOL_LOGGER_EVENT)? PROTOCOL_TYPE_EVENT:PROTOCOL_TYPE_REQUEST; elog.client_pid = client_pid; elog.target_id = wl_resource_get_id(message->resource); snprintf(elog.name, PATH_MAX,"%s:%s", wl_resource_get_class(message->resource), message->message->name); - DSLOG_DBG("DSWaylandProtocolTracePriv", "after get info protocol log => type: %s, client_pit: %d, target_id: %d, name: %s, cmd: %s", elog.type, elog.client_pid, elog.target_id, elog.name, elog.cmd); - if(!protocol_rule_validate(&elog)) return; BUF_SNPRINTF("[%10.3f] %s%d%s%s@%u.%s(", @@ -716,87 +687,65 @@ void DSWaylandProtocolTracePrivate::protocol_trace_func(void *user_data, enum wl fprintf(log_fp_ptrace, "%s\n", strbuf); else DSLOG_INF("DSWaylandProtocolTracePriv","%s", strbuf); - - DSLOG_DBG("DSWaylandProtocolTracePriv","OUT << protocol_trace_func"); - } ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::bintree_create_node(ProtocolTrace_Tree *tree) { - DSLOG_DBG("DSWaylandProtocolTracePriv","IN >> bintree_create_node"); - ProtocolTrace_Tree_Node *node = (ProtocolTrace_Tree_Node*) calloc(1, sizeof(ProtocolTrace_Tree_Node) + tree->size); // enia safety node->left = nullptr; node->right = nullptr; - DSLOG_DBG("DSWaylandProtocolTracePriv","OUT << bintree_create_node"); return node; } ProtocolTrace_Tree *DSWaylandProtocolTracePrivate::bintree_create_tree(int size) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_create_tree"); - ProtocolTrace_Tree *tree = (ProtocolTrace_Tree *)calloc(1, sizeof(ProtocolTrace_Tree) + size); // eina safety tree->size = size; tree->head = nullptr; - DSLOG_DBG("DSWaylandProtocolTracePriv", "bintree create treee => size : %d", tree->size); - - DSLOG_DBG("DSWaylandProtocolTracePriv","OUT << bintree_create_tree"); - return tree; } void DSWaylandProtocolTracePrivate::bintree_destroy_tree(ProtocolTrace_Tree *tree) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_destroy_tree"); if(tree->head) bintree_remove_node_recursive(tree->head); //free(tree); delete tree; - - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << bintree_destroy_tree"); } ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::bintree_get_head(ProtocolTrace_Tree *tree) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_get_head >> OUT"); return tree->head; } ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::bintree_get_left_child(ProtocolTrace_Tree_Node *node) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_get_left_child >> OUT"); return node->left; } void *DSWaylandProtocolTracePrivate::bintree_get_node_data(ProtocolTrace_Tree_Node *node) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_get_node_data >> OUT"); return (void*)(node+1); } ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::bintree_get_right_child(ProtocolTrace_Tree_Node *node) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_get_right_child >> OUT"); return node->right; } void DSWaylandProtocolTracePrivate::bintree_inorder_traverse(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Traverse_Cb func, void *arg) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_inorder_traverse"); if(tree->head) bintree_inorder_traverse_recursive(tree, tree->head, tree->head, func, arg); - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << bintree_inorder_traverse"); } int DSWaylandProtocolTracePrivate::bintree_inorder_traverse_recursive(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, ProtocolTrace_Tree_Traverse_Cb func, void *arg) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_inorder_traverse_recursive >> "); if(node->left) if(bintree_inorder_traverse_recursive(tree, node->left, node, func, arg)!=0) return 1; @@ -812,15 +761,12 @@ int DSWaylandProtocolTracePrivate::bintree_inorder_traverse_recursive(ProtocolTr void DSWaylandProtocolTracePrivate::bintree_postorder_traverse(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Traverse_Cb func, void *arg) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_postorder_traverse"); if(tree->head) bintree_postorder_traverse_recursive(tree, tree->head, tree->head, func, arg); - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << bintree_postorder_traverse"); } int DSWaylandProtocolTracePrivate::bintree_postorder_traverse_recursive(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, ProtocolTrace_Tree_Traverse_Cb func, void *arg) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_postorder_traverse_recursive >> "); if(node->left) if(bintree_postorder_traverse_recursive(tree, node->left, node, func, arg)!=0) return 1; @@ -833,50 +779,37 @@ int DSWaylandProtocolTracePrivate::bintree_postorder_traverse_recursive(Protocol void DSWaylandProtocolTracePrivate::bintree_remove_node(ProtocolTrace_Tree_Node *node) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_remove_node"); //free(node); delete node; - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << bintree_remove_node"); } void DSWaylandProtocolTracePrivate::bintree_remove_node_recursive(ProtocolTrace_Tree_Node *node) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_remove_node_recursive"); if(node->left) bintree_remove_node_recursive(node->left); if(node->right) bintree_remove_node_recursive(node->right); bintree_remove_node(node); - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << bintree_remove_node_recursive"); } void DSWaylandProtocolTracePrivate::bintree_set_head(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *head) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_set_head"); tree->head = head; - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << bintree_set_head"); } void DSWaylandProtocolTracePrivate::bintree_set_left_child(ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *child) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_set_left_child"); node->left = child; - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << bintree_set_left_child"); } void DSWaylandProtocolTracePrivate::bintree_set_right_child(ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *child) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> bintree_set_right_child"); node->right = child; - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << bintree_set_right_child"); } ProtocolTrace_Token DSWaylandProtocolTracePrivate::parser_next_token_get(const char **string) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> parser_next_token_get"); - DSLOG_DBG("DSWaylandProtocolTracePriv", "parameter string = %s",*string); - static int token_cnt = sizeof(token_table) / sizeof(token_table[0]); int i, compare_res, found =0, first, last; @@ -887,7 +820,6 @@ ProtocolTrace_Token DSWaylandProtocolTracePrivate::parser_next_token_get(const c while(1) { compare_res = strncmp(*string, token_table[i].token_char, token_table[i].token_length); - DSLOG_DBG("DSWaylandProtocolTracePriv", "parser_next_token_get:: i = %d// compare string -> string = %s ,vs, token_char = %s",i,*string, token_table[i].token_char); while(compare_res == 0) { found = 1; @@ -900,10 +832,7 @@ ProtocolTrace_Token DSWaylandProtocolTracePrivate::parser_next_token_get(const c if(found) { i--; - DSLOG_DBG("DSWaylandProtocolTracePriv", "parm string (before)=> %s",*string); *string += token_table[i].token_length; - DSLOG_DBG("DSWaylandProtocolTracePriv", "parm string (after = add token length) => %s",*string); - DSLOG_DBG("DSWaylandProtocolTracePriv", "parser next token => %d, token_table name = %d",i,token_table[i].token_name); return token_table[i].token_name; } @@ -921,75 +850,57 @@ ProtocolTrace_Token DSWaylandProtocolTracePrivate::parser_next_token_get(const c if(isalpha(**string)) { (*string)++; - DSLOG_DBG("DSWaylandProtocolTracePriv", "string is alpha >> next? = %c",**string); while(isalpha(**string) || isdigit(**string) || **string == '_' || **string == '-') { (*string)++; } - DSLOG_DBG("DSWaylandProtocolTracePriv", "string is alpha >> end alpha = %c",**string); return PROTOCOLTRACE_TOKEN_SYMBOL; } if(isdigit(**string)) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "string is digit = %c",**string); (*string)++; while(isdigit(**string)) (*string)++; return PROTOCOLTRACE_TOKEN_NUMBER; } - - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << parser_next_token_get"); return PROTOCOLTRACE_TOKEN_UNKNOWN; } ProtocolTrace_Tree *DSWaylandProtocolTracePrivate::protocol_parser_rule_string_parse(const char *string) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> protocol_parser_rule_string_parse"); - DSLOG_DBG("DSWaylandProtocolTracePriv", "parameter string = %s", string); - ProtocolTrace_Tree *tree; ProtocolTrace_Tree_Node *node; ProtocolTrace_Token_Data token; token.string = &string; - DSLOG_DBG("DSWaylandProtocolTracePriv", "token = %s", *token.string); parser_token_process(&token); - DSLOG_DBG("DSWaylandProtocolTracePriv", "token(after parser) = %s, %d", *token.string, token.last_token); tree = bintree_create_tree(sizeof(ProtocolTrace_Rule_Node)); if(!tree) return nullptr; node = parser_token_parse(tree, &token); - DSLOG_DBG("DSWaylandProtocolTracePriv", "get node"); if(!node) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "node is null"); bintree_destroy_tree(tree); DSLOG_DBG("DSWaylandProtocolTracePriv", "finish destroy tree & return null"); return nullptr; } bintree_set_head(tree, node); - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << protocol_parser_rule_string_parse "); return tree; } ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::parser_statement_parse(ProtocolTrace_Tree *tree, ProtocolTrace_Token_Data *token) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> parser_statement_parse"); - DSLOG_DBG("DSWaylandProtocolTracePriv", "(parameter) token->string = %s, token->last symbol =%s", *token->string, token->last_symbol); - DSLOG_DBG("DSWaylandProtocolTracePriv", "(parameter) tree_size = %d", tree->size); - ProtocolTrace_Tree_Node *node = nullptr; ProtocolTrace_Rule_Node *data; if(token->last_token == PROTOCOLTRACE_TOKEN_L_BR) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "last token = %d", PROTOCOLTRACE_TOKEN_L_BR); parser_token_process(token); node = parser_token_parse(tree, token); @@ -999,10 +910,8 @@ ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::parser_statement_parse(P if(token->last_token != PROTOCOLTRACE_TOKEN_R_BR) goto fail; - DSLOG_DBG("DSWaylandProtocolTracePriv", "not fail"); parser_token_process(token); - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << parser_statement_parse"); return node; } @@ -1023,7 +932,6 @@ ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::parser_statement_parse(P data->node_type = PROTOCOLTRACE_NODE_TYPE_ALL; parser_token_process(token); - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << parser_statement_parse"); return node; } @@ -1072,19 +980,15 @@ ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::parser_statement_parse(P parser_token_process(token); - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << parser_statement_parse"); return node; fail: if(node) bintree_remove_node_recursive(node); - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << parser_statement_parse"); return nullptr; } ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::parser_token_parse(ProtocolTrace_Tree *tree, ProtocolTrace_Token_Data *token) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> parser_token_parse"); - DSLOG_DBG("DSWaylandProtocolTracePriv", "(parameter) string = %s, last token = %d, last symbol = %s", *token->string, token->last_token, token->last_symbol); ProtocolTrace_Tree_Node *node, *left = nullptr, *right = nullptr; ProtocolTrace_Rule_Node *data; @@ -1136,107 +1040,76 @@ ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::parser_token_parse(Proto bintree_set_left_child(node, left); bintree_set_right_child(node, right); } - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << parser_token_parse"); return node; fail: DSLOG_DBG("DSWaylandProtocolTracePriv", "[fail] recursive remove node"); if(left) bintree_remove_node_recursive(left); - DSLOG_DBG("DSWaylandProtocolTracePriv", "return null"); return nullptr; } void DSWaylandProtocolTracePrivate::parser_token_process(ProtocolTrace_Token_Data *token) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> parser_token_process"); do { token->last_symbol = *(token->string); - DSLOG_DBG("DSWaylandProtocolTracePriv", "last symbol = %c", token->last_symbol); token->last_token = parser_next_token_get(token->string); - DSLOG_DBG("DSWaylandProtocolTracePriv", "last token = %d", token->last_token); token->symbol_len = *(token->string) - token->last_symbol; - DSLOG_DBG("DSWaylandProtocolTracePriv", "last_symbol : %s , last_token : %d, symbol_len : %d", token->last_symbol, token->last_token, token->symbol_len); } while (token->last_token == PROTOCOLTRACE_TOKEN_SPACE); - - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << parser_token_process"); } void DSWaylandProtocolTracePrivate::protocol_arguments_merge(char *target, int target_size, int argc, const char **argv) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> protocol_arguments_merge"); - DSLOG_DBG("DSWaylandProtocolTracePriv", "(parameter) target = %s", target); - DSLOG_DBG("DSWaylandProtocolTracePriv", "(parameter) target size= %d", target_size); - int i, len; for(i=0; i> protocol_cmd_get"); char *p; if(!path) return nullptr; p = strrchr(path, '/'); - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << protocol_cmd_get"); return (p)?p+1:path; } void DSWaylandProtocolTracePrivate::rulechecker_destroy(ProtocolTrace_Rule_Checker *rc) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rulechecker_destroy"); - int i; for(i=rc->count-1; i>=0; i--) rulechecker_rule_remove(rc,i); //free(rc); delete rc; - - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << rulechecker_destroy"); } ProtocolTrace_Rule_Checker *DSWaylandProtocolTracePrivate::rulechecker_init() { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rulechecker_init"); - ProtocolTrace_Rule_Checker *rc = (ProtocolTrace_Rule_Checker *) calloc(1, sizeof(ProtocolTrace_Rule_Checker)); if (!rc) return nullptr; rc->count = 0; - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << rulechecker_init"); - return rc; } int DSWaylandProtocolTracePrivate::rulechecker_int_compare(ProtocolTrace_Comparer comparer, int int2, int int1) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rulechecker_int_compare >> "); - switch (comparer) { case PROTOCOLTRACE_COMPARER_EQUAL: @@ -1257,9 +1130,6 @@ int DSWaylandProtocolTracePrivate::rulechecker_int_compare(ProtocolTrace_Compare ProtocolTrace_Rule_Set_Result DSWaylandProtocolTracePrivate::rulechecker_rule_add(ProtocolTrace_Rule_Checker *rc, ProtocolTrace_Policy_Type policy, const char *rule_string) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rulechecker_rule_add"); - DSLOG_DBG("DSWaylandProtocolTracePriv", "rc->count = %d", rc->count); - if(rc->count == MAX_RULE) return PROTOCOLTRACE_RULE_SET_ERR_TOO_MANY_RULES; @@ -1272,9 +1142,6 @@ ProtocolTrace_Rule_Set_Result DSWaylandProtocolTracePrivate::rulechecker_rule_ad rc->rules[rc->count].policy = policy; rc->count++; - DSLOG_DBG("DSWaylandProtocolTracePriv", "rc->rules[rc->count].policy = %d", rc->rules[rc->count -1].policy); - DSLOG_DBG("DSWaylandProtocolTracePriv", "rc->count = %d", rc->count -1); - return PROTOCOLTRACE_RULE_SET_OK; } @@ -1300,8 +1167,6 @@ void DSWaylandProtocolTracePrivate::rulechecker_rule_print(ProtocolTrace_Rule_Ch ProtocolTrace_Rule_Set_Result DSWaylandProtocolTracePrivate::rulechecker_rule_remove(ProtocolTrace_Rule_Checker *rc, int index) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rulechecker_rule_remove"); - if(index <0 || index >= rc->count) return PROTOCOLTRACE_RULE_SET_ERR_NO_RULE; @@ -1310,15 +1175,11 @@ ProtocolTrace_Rule_Set_Result DSWaylandProtocolTracePrivate::rulechecker_rule_re if(index!=rc->count) memmove(&rc->rules[index], &rc->rules[index+1], sizeof(ProtocolTrace_Rule)*(rc->count - index)); - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << rulechecker_rule_remove"); - return PROTOCOLTRACE_RULE_SET_OK; } int DSWaylandProtocolTracePrivate::rulechecker_rule_validate(ProtocolTrace_Rule_Checker *rc, int type, int target_id, const char *name, int pid, char *cmd) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rulechecker_rule_validate"); - ProtocolTrace_Validate_Args args = {type, target_id, name, pid, cmd}; ProtocolTrace_Tree_Node *node; ProtocolTrace_Rule_Node *data; @@ -1333,18 +1194,14 @@ int DSWaylandProtocolTracePrivate::rulechecker_rule_validate(ProtocolTrace_Rule_ if(data->result == PROTOCOLTRACE_RESULT_TRUE) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << rulechecker_rule_validate"); return rc->rules[i].policy == PROTOCOLTRACE_TYPE_ALLOW; } } - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << rulechecker_rule_validate"); return default_policy == PROTOCOLTRACE_TYPE_ALLOW; } int DSWaylandProtocolTracePrivate::rulechecker_string_compare(ProtocolTrace_Comparer comparer, char *str2, char *str1) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rulechecker_string_compare >> "); - int result = strcasecmp(str2, str1); switch (comparer) @@ -1401,7 +1258,6 @@ const char * DSWaylandProtocolTracePrivate::rulechecker_usage_print() int DSWaylandProtocolTracePrivate::rule_print_func(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rule_print_func"); ProtocolTrace_Reply_Buffer *buffer = (ProtocolTrace_Reply_Buffer *)arg; char *reply = *buffer->reply; int *len = buffer->len; @@ -1432,16 +1288,13 @@ int DSWaylandProtocolTracePrivate::rule_print_func(ProtocolTrace_Tree *tree, Pro } *buffer->reply = reply; - DSLOG_DBG("DSWaylandProtocolTracePriv", "buffer->reply = %s", reply); + //DSLOG_DBG("DSWaylandProtocolTracePriv", "buffer->reply = %s", reply); - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << rule_print_func"); return 0; } int DSWaylandProtocolTracePrivate::rule_validate_func(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> rule_validate_func "); - ProtocolTrace_Validate_Args *args = (ProtocolTrace_Validate_Args *)arg; ProtocolTrace_Tree_Node *left, *right; ProtocolTrace_Rule_Node *data, *left_data =nullptr, *right_data = nullptr; @@ -1544,11 +1397,8 @@ int DSWaylandProtocolTracePrivate::rule_validate_func(ProtocolTrace_Tree *tree, } else { - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << rule_validate_func "); return -1; } - - DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << rule_validate_func "); return 0; } -- 2.7.4 From 469d9132d97603cadb2ab57190e2990e5bbf9308 Mon Sep 17 00:00:00 2001 From: dyamy-lee Date: Fri, 21 Aug 2020 15:22:42 +0900 Subject: [PATCH 09/16] Add DSWaylandProtocolTrace in DSCompositor Change-Id: Ifbad214d1bc1e0dbd3cbaaf29a512ad456cdd62a --- src/DSCompositor/DSCompositor.cpp | 10 ++++++++++ src/DSCompositor/DSCompositorPrivate.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/src/DSCompositor/DSCompositor.cpp b/src/DSCompositor/DSCompositor.cpp index bda6f1d..a4cfa29 100644 --- a/src/DSCompositor/DSCompositor.cpp +++ b/src/DSCompositor/DSCompositor.cpp @@ -30,6 +30,7 @@ #include "DSSeat.h" #include "DSInput.h" #include "DSWaylandCompositor.h" +#include "DSWaylandProtocolTrace.h" #include namespace display_server @@ -88,6 +89,7 @@ DSCompositorPrivate::~DSCompositorPrivate() DSBufferManager::releaseInstance(); DSEventLoop::releaseInstance(); DSTizenAppinfoMgr::releaseInstance(); + DSWaylandProtocolTrace::releaseInstance(); } bool DSCompositorPrivate::run() @@ -99,6 +101,7 @@ bool DSCompositorPrivate::run() __initializeBufferManager(); __initializeTizenAppinfoMgr(); __initializeWindowManager(); + __initializeProtocolTrace(); __canvas = pub->_onInitialized(); if (!__canvas) { DSLOG_ERR("Compositor", "_onInitialized() fails."); @@ -164,4 +167,11 @@ void DSCompositorPrivate::__initializeWindowManager() __dsWindowMgr = DSWindowManager::getInstance(); } +void DSCompositorPrivate::__initializeProtocolTrace() +{ + __protocolTrace = DSWaylandProtocolTrace::getInstance(); + __protocolTrace->init(); + __protocolTrace->enableProtocolTrace(true); +} + } // namespace display_server diff --git a/src/DSCompositor/DSCompositorPrivate.h b/src/DSCompositor/DSCompositorPrivate.h index e926204..5f072d8 100644 --- a/src/DSCompositor/DSCompositorPrivate.h +++ b/src/DSCompositor/DSCompositorPrivate.h @@ -30,6 +30,7 @@ #include "DSBufferManager.h" #include "DSTizenAppinfoMgr.h" #include "DSWindowManager.h" +#include "DSWaylandProtocolTrace.h" namespace display_server { @@ -64,12 +65,14 @@ private: DSBufferManager *__dsBufferManager; DSTizenAppinfoMgr * __dsAppinfoMgr; DSWindowManager *__dsWindowMgr; + DSWaylandProtocolTrace *__protocolTrace; void __initializeWlDisplay(); void __initializeOutputs(); void __initializeBufferManager(); void __initializeTizenAppinfoMgr(); void __initializeWindowManager(); + void __initializeProtocolTrace(); }; } -- 2.7.4 From bca04730f96eb9746eee970c296a487e60a724eb Mon Sep 17 00:00:00 2001 From: dyamy-lee Date: Fri, 21 Aug 2020 18:32:45 +0900 Subject: [PATCH 10/16] correct typo error and defect Change-Id: Idb57323778c2cee9850a52681d7e8a676d541c44 --- src/DSCompositor/DSCompositor.cpp | 10 +- src/DSWaylandServer/DSWaylandProtocolTrace.cpp | 123 ++++++++++++++------- .../DSWaylandProtocolTracePrivate.h | 1 + tests/DSWaylandProtocolTrace-test.cpp | 4 +- 4 files changed, 95 insertions(+), 43 deletions(-) diff --git a/src/DSCompositor/DSCompositor.cpp b/src/DSCompositor/DSCompositor.cpp index a4cfa29..30e8d02 100644 --- a/src/DSCompositor/DSCompositor.cpp +++ b/src/DSCompositor/DSCompositor.cpp @@ -74,7 +74,8 @@ DSCompositorPrivate::DSCompositorPrivate(DSCompositor *p_ptr) __canvas(nullptr), __dsBufferManager(nullptr), __dsAppinfoMgr(nullptr), - __dsWindowMgr(nullptr) + __dsWindowMgr(nullptr), + __protocolTrace(nullptr) { __eventLoop = DSEventLoop::getInstance(); @@ -170,8 +171,9 @@ void DSCompositorPrivate::__initializeWindowManager() void DSCompositorPrivate::__initializeProtocolTrace() { __protocolTrace = DSWaylandProtocolTrace::getInstance(); - __protocolTrace->init(); - __protocolTrace->enableProtocolTrace(true); + if(__protocolTrace){ + if(__protocolTrace->init()) + __protocolTrace->enableProtocolTrace(true); + } } - } // namespace display_server diff --git a/src/DSWaylandServer/DSWaylandProtocolTrace.cpp b/src/DSWaylandServer/DSWaylandProtocolTrace.cpp index 97eaad0..9122a09 100644 --- a/src/DSWaylandServer/DSWaylandProtocolTrace.cpp +++ b/src/DSWaylandServer/DSWaylandProtocolTrace.cpp @@ -93,9 +93,6 @@ const char *get_next_argument(const char *signature, struct argument_details *de DSWaylandProtocolTrace::DSWaylandProtocolTrace(DSObject *parent) : DS_INIT_PRIVATE_PTR(DSWaylandProtocolTrace) { - //init(); - DS_GET_PRIV(DSWaylandProtocolTrace); - priv->__wlCompositor = DSWaylandCompositor::getInstance(); } DSWaylandProtocolTrace::~DSWaylandProtocolTrace() @@ -138,7 +135,6 @@ bool DSWaylandProtocolTrace::init(void) DS_GET_PRIV(DSWaylandProtocolTrace); bool ret = false; char *env_path = nullptr; - char tmp[PATH_MAX] = {0,}; rc = priv->rulechecker_init(); @@ -150,11 +146,10 @@ bool DSWaylandProtocolTrace::init(void) if(env_path) { - //TODO: free env_path - DSLOG_DBG("DSWaylandProtocolTrace", "delete rule file path = %s", env_path); - //free(env_path); + char *tmp = strdup(env_path); + if(!tmp) return false; + free(tmp); env_path = nullptr; - DSLOG_DBG("DSWaylandProtocolTrace", "delete rule file path done."); } if(!ret) return ret; @@ -164,13 +159,13 @@ bool DSWaylandProtocolTrace::init(void) DSLOG_DBG("DSWaylandProtocolTrace", "==================================================== trace file path = %s", env_path); ret = priv->protocol_trace_init(env_path); DSLOG_DBG("DSWaylandProtocolTrace", "result of protocol trace init = %d", ret); + if(env_path) { - //TODO: free env_path - DSLOG_DBG("DSWaylandProtocolTrace", "delete trace file path = %s", env_path); - //free(env_path); + char *tmp = strdup(env_path); + if(!tmp) return false; + free(tmp); env_path = nullptr; - DSLOG_DBG("DSWaylandProtocolTrace", "delete trace file path done."); } return ret; } @@ -219,7 +214,7 @@ bool DSWaylandProtocolTrace::updateProtocolRule(const int argc, const char **arg DSWaylandProtocolTracePrivate::DSWaylandProtocolTracePrivate(DSWaylandProtocolTrace *p_ptr) : DSObjectPrivate(p_ptr), __p_ptr(p_ptr) { - + __wlCompositor = DSWaylandCompositor::getInstance(); } DSWaylandProtocolTracePrivate::~DSWaylandProtocolTracePrivate() @@ -229,27 +224,34 @@ DSWaylandProtocolTracePrivate::~DSWaylandProtocolTracePrivate() bool DSWaylandProtocolTracePrivate::protocol_rule_init(char *rule_path) { + bool ret = false; char *argv[2]; int argc = 2; if(!rule_path || strlen(rule_path) <= 0) + { + DSLOG_ERR("DSWaylandProtocolTracePrivate", "rule path is null"); return false; + } argv[0] = "file"; argv[1] = rule_path; DSLOG_DBG("DSWaylandProtocolTracePriv", "rule_path = %s", rule_path); - protocol_rule_set(argc, (const char**)&(argv[0])); + ret = protocol_rule_set(argc, (const char**)&(argv[0])); - return true; + return ret; } bool DSWaylandProtocolTracePrivate::protocol_trace_init(char *trace_path) { DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> protocol_trace_init"); if(!trace_path || strlen(trace_path) <= 0) + { + DSLOG_ERR("DSWaylandProtocolTracePrivate", "trace path is null"); return false; + } trace_env_path = trace_path; DSLOG_DBG("DSWaylandProtocolTracePriv", "saved trace path = %s", trace_env_path); @@ -274,6 +276,38 @@ bool DSWaylandProtocolTracePrivate::protocol_trace_init(char *trace_path) return true; } +int DSWaylandProtocolTracePrivate::chk(const char *str) +{ + char *endptr; + int index = strtol(str, &endptr, 10); + if(errno == ERANGE) + { + DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : overflow"); + return -1; + } + if(errno != 0) + { + DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : other error"); + return -1; + } + if(endptr == 0) + { + DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : non-numeric"); + return -1; + } + if(*endptr != '\0') + { + DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : non-numeric at end"); + return -1; + } + if(isspace(*str)) + { + DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : space at beginning"); + return -1; + } + return index; +} + bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char **argv) { DSLOG_DBG("DSWaylandProtocolTracePriv", "IN >> protocol_rule_set"); @@ -361,7 +395,7 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char } else if(result == PROTOCOLTRACE_RULE_SET_ERR_PARSE) { - DSLOG_ERR("DSWaylandProtocolTracePriv", "Error: An error occured during parsing the rule [%s]", rule); + DSLOG_ERR("DSWaylandProtocolTracePriv", "Error: An error occurred during parsing the rule [%s]", rule); return false; } DSLOG_INF("DSWaylandProtocolTracePriv", "The rule was successfully added"); @@ -398,13 +432,20 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char } else { - int index = atoi(remove_idx); - DSLOG_DBG("DSWaylandProtocolTracePriv", "REMOVE :: remove idx = %d", index); - - if(isdigit(*remove_idx) && rulechecker_rule_remove(rc, index) == 0) - DSLOG_INF("DSWaylandProtocolTracePriv", "The rule [%d] was successfully removed.", index); + int index = chk(remove_idx); + if(index == -1) + { + DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : overflow"); + } else - DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : No such rule [%s]", remove_idx); + { + DSLOG_DBG("DSWaylandProtocolTracePriv", "REMOVE :: remove idx = %d", index); + + if(isdigit(*remove_idx) && rulechecker_rule_remove(rc, index) == 0) + DSLOG_INF("DSWaylandProtocolTracePriv", "The rule [%d] was successfully removed.", index); + else + DSLOG_ERR("DSWaylandProtocolTracePriv", "Rule remove fail : No such rule [%s]", remove_idx); + } } } rulechecker_rule_print(rc); @@ -438,7 +479,7 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char return true; } - DSLOG_ERR("DSWaylandProtocolTracePriv", "%s\nUnkown command : [%s] ", rulechecker_usage_print(), command); + DSLOG_ERR("DSWaylandProtocolTracePriv", "%s\nUnknown command : [%s] ", rulechecker_usage_print(), command); DSLOG_DBG("DSWaylandProtocolTracePriv", "OUT << protocol_rule_set"); @@ -454,7 +495,7 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_file_set(const char *filename) fd = open(filename, O_RDONLY); if(fd<0) { - DSLOG_DBG("DSWaylandProtocolTracePriv", "failed: open '%s'", filename); + DSLOG_ERR("DSWaylandProtocolTracePriv", "failed: open '%s'", filename); return false; } @@ -577,8 +618,7 @@ void DSWaylandProtocolTracePrivate::wl_protocol_cb_client_destroy(struct wl_list DSLOG_INF("DSWaylandProtocolTracePriv", "%s", strbuf); wl_list_remove(&listener->link); - //free(listener); - delete listener; + free(listener); listener = nullptr; } @@ -593,6 +633,8 @@ void DSWaylandProtocolTracePrivate::protocol_client_destroy_listener_reg(struct destroy_listener = (struct wl_listener *)calloc(1, sizeof(wl_listener)); //EINA_SAFETY_ON_NULL_RETURN(destroy_listener); + if(!destroy_listener) + return; destroy_listener->notify = wl_protocol_cb_client_destroy; wl_client_add_destroy_listener(client, destroy_listener); @@ -693,6 +735,8 @@ ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::bintree_create_node(Prot { ProtocolTrace_Tree_Node *node = (ProtocolTrace_Tree_Node*) calloc(1, sizeof(ProtocolTrace_Tree_Node) + tree->size); // enia safety + if(!node) + return nullptr; node->left = nullptr; node->right = nullptr; @@ -704,6 +748,8 @@ ProtocolTrace_Tree *DSWaylandProtocolTracePrivate::bintree_create_tree(int size) { ProtocolTrace_Tree *tree = (ProtocolTrace_Tree *)calloc(1, sizeof(ProtocolTrace_Tree) + size); // eina safety + if(!tree) + return nullptr; tree->size = size; tree->head = nullptr; @@ -714,8 +760,7 @@ void DSWaylandProtocolTracePrivate::bintree_destroy_tree(ProtocolTrace_Tree *tre { if(tree->head) bintree_remove_node_recursive(tree->head); - //free(tree); - delete tree; + free(tree); } ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::bintree_get_head(ProtocolTrace_Tree *tree) @@ -779,8 +824,7 @@ int DSWaylandProtocolTracePrivate::bintree_postorder_traverse_recursive(Protocol void DSWaylandProtocolTracePrivate::bintree_remove_node(ProtocolTrace_Tree_Node *node) { - //free(node); - delete node; + free(node); } void DSWaylandProtocolTracePrivate::bintree_remove_node_recursive(ProtocolTrace_Tree_Node *node) @@ -919,7 +963,7 @@ ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::parser_statement_parse(P goto fail; node = bintree_create_node(tree); - //eina safty + //eina safety data = (ProtocolTrace_Rule_Node *) bintree_get_node_data(node); @@ -981,6 +1025,7 @@ ProtocolTrace_Tree_Node *DSWaylandProtocolTracePrivate::parser_statement_parse(P parser_token_process(token); return node; + fail: if(node) bintree_remove_node_recursive(node); @@ -1093,8 +1138,7 @@ void DSWaylandProtocolTracePrivate::rulechecker_destroy(ProtocolTrace_Rule_Check for(i=rc->count-1; i>=0; i--) rulechecker_rule_remove(rc,i); - //free(rc); - delete rc; + free(rc); } ProtocolTrace_Rule_Checker *DSWaylandProtocolTracePrivate::rulechecker_init() @@ -1147,8 +1191,10 @@ ProtocolTrace_Rule_Set_Result DSWaylandProtocolTracePrivate::rulechecker_rule_ad void DSWaylandProtocolTracePrivate::rulechecker_rule_print(ProtocolTrace_Rule_Checker *rc) { - char *reply; - int *len; + char tmpReply[4096]; + int tmpLen = sizeof(tmpReply); + char *reply = tmpReply; + int *len = &tmpLen; ProtocolTrace_Reply_Buffer buffer = {&reply, len}; int i; @@ -1322,11 +1368,12 @@ int DSWaylandProtocolTracePrivate::rule_validate_func(ProtocolTrace_Tree *tree, } else if(data->node_type == PROTOCOLTRACE_NODE_TYPE_DATA) { - char iface[64]; + char iface[64] = {0,}; char *msg = nullptr; + int colon = atoi(":"); if(args->name) - msg = ":";//index(args->name, ":"); + msg = (char *) index(args->name, colon); if(msg) { int min = MIN(sizeof(iface)-1, msg-args->name); @@ -1354,7 +1401,7 @@ int DSWaylandProtocolTracePrivate::rule_validate_func(ProtocolTrace_Tree *tree, } else if(!strcasecmp(data->variable_name, "IFACE")) { - if(msg && rulechecker_string_compare(data->comparer, data->value.string, iface)) + if(msg && !iface[0] && rulechecker_string_compare(data->comparer, data->value.string, iface)) data->result = PROTOCOLTRACE_RESULT_TRUE; else data->result = PROTOCOLTRACE_RESULT_FALSE; diff --git a/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h b/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h index 8c22087..ffecf2d 100644 --- a/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h +++ b/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h @@ -283,6 +283,7 @@ private: const char * rulechecker_usage_print(); static int rule_print_func(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg); static int rule_validate_func(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg); + int chk(const char *str); }; } diff --git a/tests/DSWaylandProtocolTrace-test.cpp b/tests/DSWaylandProtocolTrace-test.cpp index 63d0e67..31201ff 100644 --- a/tests/DSWaylandProtocolTrace-test.cpp +++ b/tests/DSWaylandProtocolTrace-test.cpp @@ -30,7 +30,9 @@ class DSWaylandProtocolTraceTest : public ::testing::Test { public: void SetUp(void) override - {} + { + setenv("XDG_RUNTIME_DIR", "/run", 1); + } void TearDown(void) override {} -- 2.7.4 From 35fea3086fcc142b010b05966a2299c3be3fdb06 Mon Sep 17 00:00:00 2001 From: dyamy-lee Date: Thu, 27 Aug 2020 19:40:38 +0900 Subject: [PATCH 11/16] fix not working trace by rule without all case and add log about cmd part Change-Id: Ic6696761b25ee43276a05b0cc09df0e96be6be25 --- src/DSWaylandServer/DSWaylandProtocolTrace.cpp | 47 ++++++++++++++++++++-- .../DSWaylandProtocolTracePrivate.h | 1 + 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/DSWaylandServer/DSWaylandProtocolTrace.cpp b/src/DSWaylandServer/DSWaylandProtocolTrace.cpp index 9122a09..1d4194f 100644 --- a/src/DSWaylandServer/DSWaylandProtocolTrace.cpp +++ b/src/DSWaylandServer/DSWaylandProtocolTrace.cpp @@ -23,6 +23,7 @@ #include "DSWaylandProtocolTrace.h" #include "DSWaylandProtocolTracePrivate.h" +#include "DSWaylandClient.h" #include #include @@ -552,6 +553,31 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_validate(ProtocolTrace_Protoco return rulechecker_rule_validate(rc, log->type, log->target_id, log->name, log->client_pid, cmd); } +void DSWaylandProtocolTracePrivate::wl_client_proc_name_get(pid_t pid, char *name, int size) + { + if(!name) return; + + FILE *h; + char proc[512], pname[512]; + size_t len; + + snprintf(proc, 512, "/proc/%d/cmdline", pid); + + h = fopen(proc, "r"); + if(!h) return; + + len = fread(pname, sizeof(char), 512, h); + if(len >0) + pname[len-1]='\0'; + else + { + strncpy(pname, "NO NAME", sizeof(pname)); + } + fclose(h); + + strncpy(name, pname, size); +} + void DSWaylandProtocolTracePrivate::protocol_trace_set(void) { DSLOG_DBG("DSWaylandProtocolTracePriv","IN >> protocol trace set"); @@ -575,7 +601,7 @@ void DSWaylandProtocolTracePrivate::protocol_trace_set(void) DSLOG_DBG("DSWaylandProtocolTracePriv","get display "); //check working - ds_wl_protocol_logger = wl_display_add_protocol_logger(display, protocol_trace_func, nullptr); + ds_wl_protocol_logger = wl_display_add_protocol_logger(display, protocol_trace_func, __wlCompositor); DSLOG_DBG("DSWaylandProtocolTracePriv","OUT << protocol trace set"); } @@ -671,6 +697,18 @@ void DSWaylandProtocolTracePrivate::protocol_trace_func(void *user_data, enum wl elog.target_id = wl_resource_get_id(message->resource); snprintf(elog.name, PATH_MAX,"%s:%s", wl_resource_get_class(message->resource), message->message->name); + DSWaylandCompositor * comp = (DSWaylandCompositor * )user_data; + std::list clients = comp->clients(); + for(auto client : clients) + { + char name[512]; + wl_client_proc_name_get(client->pid(), name, sizeof(name)); + if(client->pid() == client_pid) + { + snprintf(elog.cmd, PATH_MAX, "%s", name); + } + } + if(!protocol_rule_validate(&elog)) return; BUF_SNPRINTF("[%10.3f] %s%d%s%s@%u.%s(", @@ -1370,10 +1408,11 @@ int DSWaylandProtocolTracePrivate::rule_validate_func(ProtocolTrace_Tree *tree, { char iface[64] = {0,}; char *msg = nullptr; - int colon = atoi(":"); if(args->name) - msg = (char *) index(args->name, colon); + { + msg = (char *) strchr(args->name, ':'); + } if(msg) { int min = MIN(sizeof(iface)-1, msg-args->name); @@ -1401,7 +1440,7 @@ int DSWaylandProtocolTracePrivate::rule_validate_func(ProtocolTrace_Tree *tree, } else if(!strcasecmp(data->variable_name, "IFACE")) { - if(msg && !iface[0] && rulechecker_string_compare(data->comparer, data->value.string, iface)) + if(msg && iface[0] && rulechecker_string_compare(data->comparer, data->value.string, iface)) data->result = PROTOCOLTRACE_RESULT_TRUE; else data->result = PROTOCOLTRACE_RESULT_FALSE; diff --git a/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h b/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h index ffecf2d..569b462 100644 --- a/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h +++ b/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h @@ -284,6 +284,7 @@ private: static int rule_print_func(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg); static int rule_validate_func(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg); int chk(const char *str); + static void wl_client_proc_name_get(pid_t pid, char *name, int size); }; } -- 2.7.4 From 9a000fb324467a028fbf0bc25b3cfea3fee06a97 Mon Sep 17 00:00:00 2001 From: dyamy-lee Date: Fri, 28 Aug 2020 10:09:44 +0900 Subject: [PATCH 12/16] fix the warning issues Change-Id: I7638271160cc6a31201b0c98a0e66ff0159b29c6 --- src/DSWaylandServer/DSWaylandProtocolTrace.cpp | 31 ++++++++++++---------- .../DSWaylandProtocolTracePrivate.h | 8 +++--- tests/DSWaylandProtocolTrace-test.cpp | 2 +- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/DSWaylandServer/DSWaylandProtocolTrace.cpp b/src/DSWaylandServer/DSWaylandProtocolTrace.cpp index 1d4194f..75d8583 100644 --- a/src/DSWaylandServer/DSWaylandProtocolTrace.cpp +++ b/src/DSWaylandServer/DSWaylandProtocolTrace.cpp @@ -226,7 +226,7 @@ DSWaylandProtocolTracePrivate::~DSWaylandProtocolTracePrivate() bool DSWaylandProtocolTracePrivate::protocol_rule_init(char *rule_path) { bool ret = false; - char *argv[2]; + const char *argv[2]; int argc = 2; if(!rule_path || strlen(rule_path) <= 0) @@ -330,7 +330,7 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char ProtocolTrace_Rule_Set_Result result; const char * policy = argv[1]; //allow, deny char merge[8192] = {0,}, rule[8192] = {0,}; - int i, index=0, size_rule, apply = 0; + int i, index=0, size_rule, apply = 0, size_merge; if(argc <3) { @@ -354,8 +354,9 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_set(const int argc, const char protocol_arguments_merge(merge, sizeof(merge), argc -2, &(argv[2])); size_rule = sizeof(rule) -1; + size_merge = strlen(merge); - for(i=0; isize_rule) return false; @@ -506,7 +508,7 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_file_set(const char *filename) while(pfs -fs < rule_len) { int i, new_argc =3; - char *new_argv[3] = {"add", }; + const char *new_argv[3] = {"add", }; char policy[64] = {0,}; char rule[1024] = {0,}; @@ -543,7 +545,7 @@ bool DSWaylandProtocolTracePrivate::protocol_rule_file_set(const char *filename) bool DSWaylandProtocolTracePrivate::protocol_rule_validate(ProtocolTrace_Protocol_Log *log) { - char *cmd = ""; + const char *cmd = ""; if(!rc) return false; @@ -1262,7 +1264,7 @@ ProtocolTrace_Rule_Set_Result DSWaylandProtocolTracePrivate::rulechecker_rule_re return PROTOCOLTRACE_RULE_SET_OK; } -int DSWaylandProtocolTracePrivate::rulechecker_rule_validate(ProtocolTrace_Rule_Checker *rc, int type, int target_id, const char *name, int pid, char *cmd) +int DSWaylandProtocolTracePrivate::rulechecker_rule_validate(ProtocolTrace_Rule_Checker *rc, int type, int target_id, const char *name, int pid, const char *cmd) { ProtocolTrace_Validate_Args args = {type, target_id, name, pid, cmd}; ProtocolTrace_Tree_Node *node; @@ -1284,7 +1286,7 @@ int DSWaylandProtocolTracePrivate::rulechecker_rule_validate(ProtocolTrace_Rule_ return default_policy == PROTOCOLTRACE_TYPE_ALLOW; } -int DSWaylandProtocolTracePrivate::rulechecker_string_compare(ProtocolTrace_Comparer comparer, char *str2, char *str1) +int DSWaylandProtocolTracePrivate::rulechecker_string_compare(ProtocolTrace_Comparer comparer, char *str2, const char *str1) { int result = strcasecmp(str2, str1); @@ -1344,8 +1346,8 @@ int DSWaylandProtocolTracePrivate::rule_print_func(ProtocolTrace_Tree *tree, Pro { ProtocolTrace_Reply_Buffer *buffer = (ProtocolTrace_Reply_Buffer *)arg; char *reply = *buffer->reply; - int *len = buffer->len; - char *operators[] = {"==", "<", ">", "<=", ">=", "!=" }; + //int *len = buffer->len; + const char *operators[] = {"==", "<", ">", "<=", ">=", "!=" }; ProtocolTrace_Rule_Node *data; data = (ProtocolTrace_Rule_Node *)bintree_get_node_data(node); @@ -1415,14 +1417,15 @@ int DSWaylandProtocolTracePrivate::rule_validate_func(ProtocolTrace_Tree *tree, } if(msg) { - int min = MIN(sizeof(iface)-1, msg-args->name); + int size_iface = sizeof(iface) -1; + int min = MIN(size_iface, msg-args->name); strncpy(iface, args->name, min); iface[min] = '\0'; msg++; } if(!strcasecmp(data->variable_name, "TYPE")) { - char *type_string; + const char *type_string; if(args->type == 0) type_string = "REQUEST"; else if(args->type == 1) @@ -1440,7 +1443,7 @@ int DSWaylandProtocolTracePrivate::rule_validate_func(ProtocolTrace_Tree *tree, } else if(!strcasecmp(data->variable_name, "IFACE")) { - if(msg && iface[0] && rulechecker_string_compare(data->comparer, data->value.string, iface)) + if(msg && iface[0] && rulechecker_string_compare(data->comparer, data->value.string, (const char *)iface)) data->result = PROTOCOLTRACE_RESULT_TRUE; else data->result = PROTOCOLTRACE_RESULT_FALSE; diff --git a/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h b/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h index 569b462..d387a9f 100644 --- a/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h +++ b/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h @@ -31,7 +31,7 @@ #include #include -#define PATH_MAX 255 //tmp 255 +#define PATH_MAX 512 #ifndef MAX #define MAX(x, y) (((x) > (y)) ? (x) : (y)) @@ -210,7 +210,7 @@ typedef struct int target_id; const char *name; int pid; - char *cmd; + const char *cmd; } ProtocolTrace_Validate_Args; typedef struct @@ -278,8 +278,8 @@ private: ProtocolTrace_Rule_Set_Result rulechecker_rule_add(_ProtocolTrace_Rule_Checker *rc, ProtocolTrace_Policy_Type policy, const char *rule_string); void rulechecker_rule_print(ProtocolTrace_Rule_Checker *rc); ProtocolTrace_Rule_Set_Result rulechecker_rule_remove(ProtocolTrace_Rule_Checker *rc, int index); - static int rulechecker_rule_validate(ProtocolTrace_Rule_Checker *rc, int type, int target_id, const char *name, int pid, char *cmd); - static int rulechecker_string_compare(ProtocolTrace_Comparer comparer, char *str2, char *str1); + static int rulechecker_rule_validate(ProtocolTrace_Rule_Checker *rc, int type, int target_id, const char *name, int pid, const char *cmd); + static int rulechecker_string_compare(ProtocolTrace_Comparer comparer, char *str2, const char *str1); const char * rulechecker_usage_print(); static int rule_print_func(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg); static int rule_validate_func(ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg); diff --git a/tests/DSWaylandProtocolTrace-test.cpp b/tests/DSWaylandProtocolTrace-test.cpp index 31201ff..3139fd4 100644 --- a/tests/DSWaylandProtocolTrace-test.cpp +++ b/tests/DSWaylandProtocolTrace-test.cpp @@ -67,7 +67,7 @@ TEST_F(DSWaylandProtocolTraceTest, DSWaylandProtocolTraceUpdateRule) pTrace->init(); int argc = 3; - char *argv[3]; + const char *argv[3]; argv[0] = "add"; argv[1] = "ALLOW"; argv[2] = "all"; -- 2.7.4 From 0ce3b859d7779d626ef434d70ab01b2f06a7e905 Mon Sep 17 00:00:00 2001 From: dyamy-lee Date: Fri, 28 Aug 2020 13:23:25 +0900 Subject: [PATCH 13/16] separate structures in DSWaylandProtocolTracePrivate.h to DSWaylandProtocolTraceStruct.h Change-Id: I0f49469d9a5daaea37626043c7713fca19a3d91c --- src/DSWaylandServer/DSWaylandProtocolTrace.h | 1 - .../DSWaylandProtocolTracePrivate.h | 187 +----------------- src/DSWaylandServer/DSWaylandProtocolTraceStruct.h | 218 +++++++++++++++++++++ src/meson.build | 3 +- 4 files changed, 221 insertions(+), 188 deletions(-) create mode 100644 src/DSWaylandServer/DSWaylandProtocolTraceStruct.h diff --git a/src/DSWaylandServer/DSWaylandProtocolTrace.h b/src/DSWaylandServer/DSWaylandProtocolTrace.h index b53e999..59cbbf0 100644 --- a/src/DSWaylandServer/DSWaylandProtocolTrace.h +++ b/src/DSWaylandServer/DSWaylandProtocolTrace.h @@ -51,7 +51,6 @@ private: static std::mutex __mutex; static DSWaylandProtocolTrace *__protocolTrace; static int __refCount; - }; } diff --git a/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h b/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h index d387a9f..a64c0db 100644 --- a/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h +++ b/src/DSWaylandServer/DSWaylandProtocolTracePrivate.h @@ -25,200 +25,15 @@ #define __DS_WAYLAND_PROTOCOL_TRACE_PRIVATE_H__ #include "DSWaylandProtocolTrace.h" -//#include "DSWaylandProtocolTraceStruct.h" +#include "DSWaylandProtocolTraceStruct.h" #include #include #include #include -#define PATH_MAX 512 - -#ifndef MAX -#define MAX(x, y) (((x) > (y)) ? (x) : (y)) -#endif - -#ifndef MIN -#define MIN(x, y) (((x) < (y)) ? (x) : (y)) -#endif - -#define BUF_SNPRINTF(fmt, ARG...) do { \ - str_l = snprintf(str_buff, str_r, fmt, ##ARG); \ - str_buff += str_l; \ - str_r -= str_l; \ -} while(0) - - -/* -#ifndef REPLY - #define REPLY(fmt, ARG...) \ - do { \ - if (reply && len && *len > 0) \ - { \ - int s = snprintf(reply, *len, fmt, ##ARG); \ - reply += s; \ - *len -= s; \ - } \ - } while (0) -#endif -*/ -#define MAX_RULE 64 -#define STRING_MAX 64 namespace display_server { -typedef struct _ProtocolTrace_Tree_Node ProtocolTrace_Tree_Node; -typedef struct _ProtocolTrace_Tree ProtocolTrace_Tree; -typedef struct _ProtocolTrace_Token_Data ProtocolTrace_Token_Data; -typedef struct _ProtocolTrace_Rule_Node ProtocolTrace_Rule_Node; -typedef struct _ProtocolTrace_Rule ProtocolTrace_Rule; -typedef struct _ProtocolTrace_Rule_Checker ProtocolTrace_Rule_Checker; -typedef struct _ProtocolTrace_Protocol_Log ProtocolTrace_Protocol_Log; - -typedef int (*ProtocolTrace_Tree_Traverse_Cb) (ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg); - -struct _ProtocolTrace_Tree_Node -{ - ProtocolTrace_Tree_Node *left; - ProtocolTrace_Tree_Node *right; -}; - -struct _ProtocolTrace_Tree -{ - int size; - ProtocolTrace_Tree_Node *head; -}; - -typedef enum -{ - PROTOCOLTRACE_TOKEN_UNKNOWN = 0, - PROTOCOLTRACE_TOKEN_L_BR =1, - PROTOCOLTRACE_TOKEN_R_BR =2, - PROTOCOLTRACE_TOKEN_NOT_EQ=3, - PROTOCOLTRACE_TOKEN_EQUAL=4, - PROTOCOLTRACE_TOKEN_LSS_THAN=5, - PROTOCOLTRACE_TOKEN_LSS_EQ =6, - PROTOCOLTRACE_TOKEN_GRT_THAN=7, - PROTOCOLTRACE_TOKEN_GRT_EQ =8, - PROTOCOLTRACE_TOKEN_AND=9, - PROTOCOLTRACE_TOKEN_OR=10, - PROTOCOLTRACE_TOKEN_SPACE=11, - PROTOCOLTRACE_TOKEN_SYMBOL=12, - PROTOCOLTRACE_TOKEN_NUMBER=13, - PROTOCOLTRACE_TOKEN_EOS=14, -} ProtocolTrace_Token; - -struct _ProtocolTrace_Token_Data -{ - const char **string; - ProtocolTrace_Token last_token; - const char *last_symbol; - int symbol_len; -}; -typedef enum -{ - PROTOCOLTRACE_NODE_TYPE_NONE, - PROTOCOLTRACE_NODE_TYPE_AND, - PROTOCOLTRACE_NODE_TYPE_OR, - PROTOCOLTRACE_NODE_TYPE_DATA, - PROTOCOLTRACE_NODE_TYPE_ALL -} ProtocolTrace_Node_Type; - -typedef enum -{ - PROTOCOLTRACE_COMPARER_EQUAL, - PROTOCOLTRACE_COMPARER_LESS, - PROTOCOLTRACE_COMPARER_GREATER, - PROTOCOLTRACE_COMPARER_LESS_EQ, - PROTOCOLTRACE_COMPARER_GREATE_EQ, - PROTOCOLTRACE_COMPARER_NOT_EQ -} ProtocolTrace_Comparer; - -typedef enum -{ - PROTOCOLTRACE_DATA_TYPE_INTEGER, - PROTOCOLTRACE_DATA_TYPE_STRING -} ProtocolTrace_Data_Type; - -typedef enum -{ - PROTOCOLTRACE_RESULT_UNKNOWN, - PROTOCOLTRACE_RESULT_TRUE, - PROTOCOLTRACE_RESULT_FALSE -} ProtocolTrace_Result_Type; - -struct _ProtocolTrace_Rule_Node -{ - ProtocolTrace_Node_Type node_type; - char variable_name[STRING_MAX]; - ProtocolTrace_Comparer comparer; - ProtocolTrace_Data_Type value_type; - - union - { - char string[STRING_MAX]; - int integer; - }value; - - ProtocolTrace_Result_Type result; -}; - -typedef enum -{ - PROTOCOLTRACE_POLICY_TYPE_UNDEFINED, - PROTOCOLTRACE_TYPE_ALLOW, - PROTOCOLTRACE_TYPE_DENY -} ProtocolTrace_Policy_Type; - -struct _ProtocolTrace_Rule -{ - ProtocolTrace_Policy_Type policy; - ProtocolTrace_Tree *tree; -}; - -struct _ProtocolTrace_Rule_Checker -{ - ProtocolTrace_Rule rules[MAX_RULE]; - int count; -}; -typedef enum -{ - PROTOCOLTRACE_RULE_SET_OK, - PROTOCOLTRACE_RULE_SET_ERR_TOO_MANY_RULES, - PROTOCOLTRACE_RULE_SET_ERR_PARSE, - PROTOCOLTRACE_RULE_SET_ERR_NO_RULE - } ProtocolTrace_Rule_Set_Result; -typedef enum{ - PROTOCOL_TYPE_REQUEST, - PROTOCOL_TYPE_EVENT -} ProtocolTrace_Protocol_Type; -struct _ProtocolTrace_Protocol_Log -{ - ProtocolTrace_Protocol_Type type; - int client_pid; - int target_id; - char name[PATH_MAX +1]; - char cmd[PATH_MAX +1]; -}; -struct argument_details { - char type; - int nullable; -}; - -typedef struct -{ - int type; - int target_id; - const char *name; - int pid; - const char *cmd; -} ProtocolTrace_Validate_Args; - -typedef struct -{ - char **reply; - int *len; -} ProtocolTrace_Reply_Buffer; - class DSWaylandProtocolTracePrivate : public DSObjectPrivate { DS_PIMPL_USE_PUBLIC(DSWaylandProtocolTrace); diff --git a/src/DSWaylandServer/DSWaylandProtocolTraceStruct.h b/src/DSWaylandServer/DSWaylandProtocolTraceStruct.h new file mode 100644 index 0000000..a1129cd --- /dev/null +++ b/src/DSWaylandServer/DSWaylandProtocolTraceStruct.h @@ -0,0 +1,218 @@ +/* +* Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#ifndef __DS_WAYLAND_PROTOCOL_TRACE_STRUCT_H__ +#define __DS_WAYLAND_PROTOCOL_TRACE_STRUCT_H__ + +#define PATH_MAX 512 +#define MAX_RULE 64 +#define STRING_MAX 64 + +#ifndef MAX +#define MAX(x, y) (((x) > (y)) ? (x) : (y)) +#endif + +#ifndef MIN +#define MIN(x, y) (((x) < (y)) ? (x) : (y)) +#endif + +#define BUF_SNPRINTF(fmt, ARG...) do { \ + str_l = snprintf(str_buff, str_r, fmt, ##ARG); \ + str_buff += str_l; \ + str_r -= str_l; \ +} while(0) + +/* +#ifndef REPLY + #define REPLY(fmt, ARG...) \ + do { \ + if (reply && len && *len > 0) \ + { \ + int s = snprintf(reply, *len, fmt, ##ARG); \ + reply += s; \ + *len -= s; \ + } \ + } while (0) +#endif +*/ + +namespace display_server +{ + +typedef struct _ProtocolTrace_Tree_Node ProtocolTrace_Tree_Node; +typedef struct _ProtocolTrace_Tree ProtocolTrace_Tree; +typedef struct _ProtocolTrace_Token_Data ProtocolTrace_Token_Data; +typedef struct _ProtocolTrace_Rule_Node ProtocolTrace_Rule_Node; +typedef struct _ProtocolTrace_Rule ProtocolTrace_Rule; +typedef struct _ProtocolTrace_Rule_Checker ProtocolTrace_Rule_Checker; +typedef struct _ProtocolTrace_Protocol_Log ProtocolTrace_Protocol_Log; + +typedef int (*ProtocolTrace_Tree_Traverse_Cb) (ProtocolTrace_Tree *tree, ProtocolTrace_Tree_Node *node, ProtocolTrace_Tree_Node *parent, void *arg); + +struct _ProtocolTrace_Tree_Node +{ + ProtocolTrace_Tree_Node *left; + ProtocolTrace_Tree_Node *right; +}; + +struct _ProtocolTrace_Tree +{ + int size; + ProtocolTrace_Tree_Node *head; +}; + +typedef enum +{ + PROTOCOLTRACE_TOKEN_UNKNOWN = 0, + PROTOCOLTRACE_TOKEN_L_BR =1, + PROTOCOLTRACE_TOKEN_R_BR =2, + PROTOCOLTRACE_TOKEN_NOT_EQ=3, + PROTOCOLTRACE_TOKEN_EQUAL=4, + PROTOCOLTRACE_TOKEN_LSS_THAN=5, + PROTOCOLTRACE_TOKEN_LSS_EQ =6, + PROTOCOLTRACE_TOKEN_GRT_THAN=7, + PROTOCOLTRACE_TOKEN_GRT_EQ =8, + PROTOCOLTRACE_TOKEN_AND=9, + PROTOCOLTRACE_TOKEN_OR=10, + PROTOCOLTRACE_TOKEN_SPACE=11, + PROTOCOLTRACE_TOKEN_SYMBOL=12, + PROTOCOLTRACE_TOKEN_NUMBER=13, + PROTOCOLTRACE_TOKEN_EOS=14, +} ProtocolTrace_Token; + +struct _ProtocolTrace_Token_Data +{ + const char **string; + ProtocolTrace_Token last_token; + const char *last_symbol; + int symbol_len; +}; +typedef enum +{ + PROTOCOLTRACE_NODE_TYPE_NONE, + PROTOCOLTRACE_NODE_TYPE_AND, + PROTOCOLTRACE_NODE_TYPE_OR, + PROTOCOLTRACE_NODE_TYPE_DATA, + PROTOCOLTRACE_NODE_TYPE_ALL +} ProtocolTrace_Node_Type; + +typedef enum +{ + PROTOCOLTRACE_COMPARER_EQUAL, + PROTOCOLTRACE_COMPARER_LESS, + PROTOCOLTRACE_COMPARER_GREATER, + PROTOCOLTRACE_COMPARER_LESS_EQ, + PROTOCOLTRACE_COMPARER_GREATE_EQ, + PROTOCOLTRACE_COMPARER_NOT_EQ +} ProtocolTrace_Comparer; + +typedef enum +{ + PROTOCOLTRACE_DATA_TYPE_INTEGER, + PROTOCOLTRACE_DATA_TYPE_STRING +} ProtocolTrace_Data_Type; + +typedef enum +{ + PROTOCOLTRACE_RESULT_UNKNOWN, + PROTOCOLTRACE_RESULT_TRUE, + PROTOCOLTRACE_RESULT_FALSE +} ProtocolTrace_Result_Type; + +struct _ProtocolTrace_Rule_Node +{ + ProtocolTrace_Node_Type node_type; + char variable_name[STRING_MAX]; + ProtocolTrace_Comparer comparer; + ProtocolTrace_Data_Type value_type; + + union + { + char string[STRING_MAX]; + int integer; + }value; + + ProtocolTrace_Result_Type result; +}; + +typedef enum +{ + PROTOCOLTRACE_POLICY_TYPE_UNDEFINED, + PROTOCOLTRACE_TYPE_ALLOW, + PROTOCOLTRACE_TYPE_DENY +} ProtocolTrace_Policy_Type; + +struct _ProtocolTrace_Rule +{ + ProtocolTrace_Policy_Type policy; + ProtocolTrace_Tree *tree; +}; + +struct _ProtocolTrace_Rule_Checker +{ + ProtocolTrace_Rule rules[MAX_RULE]; + int count; +}; +typedef enum +{ + PROTOCOLTRACE_RULE_SET_OK, + PROTOCOLTRACE_RULE_SET_ERR_TOO_MANY_RULES, + PROTOCOLTRACE_RULE_SET_ERR_PARSE, + PROTOCOLTRACE_RULE_SET_ERR_NO_RULE + } ProtocolTrace_Rule_Set_Result; +typedef enum{ + PROTOCOL_TYPE_REQUEST, + PROTOCOL_TYPE_EVENT +} ProtocolTrace_Protocol_Type; +struct _ProtocolTrace_Protocol_Log +{ + ProtocolTrace_Protocol_Type type; + int client_pid; + int target_id; + char name[PATH_MAX +1]; + char cmd[PATH_MAX +1]; +}; +struct argument_details { + char type; + int nullable; +}; + +typedef struct +{ + int type; + int target_id; + const char *name; + int pid; + const char *cmd; +} ProtocolTrace_Validate_Args; + +typedef struct +{ + char **reply; + int *len; +} ProtocolTrace_Reply_Buffer; + +} + + +#endif //__DS_WAYLAND_PROTOCOL_TRACE_STRUCT_H__ \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index ea39c2c..62c7b30 100644 --- a/src/meson.build +++ b/src/meson.build @@ -177,13 +177,14 @@ libds_wayland_srcs = [ 'DSWaylandServer/DSWaylandTizenLaunchSplash.h', 'DSWaylandServer/DSWaylandTizenLaunchSplash.cpp', 'DSWaylandServer/DSWaylandProtocolTracePrivate.h', + 'DSWaylandServer/DSWaylandProtocolTraceStruct.h', 'DSWaylandServer/DSWaylandProtocolTrace.h', 'DSWaylandServer/DSWaylandProtocolTrace.cpp', 'DSWaylandServer/DSWaylandTizenPolicyExt.h', 'DSWaylandServer/DSWaylandTizenPolicyExtPrivate.h', 'DSWaylandServer/DSWaylandTizenPolicyExt.cpp', 'DSWaylandServer/tizen_policy_ext-server-protocol.h', - 'DSWaylandServer/tizen_policy_ext-protocol.c', + 'DSWaylandServer/tizen_policy_ext-protocol.c', ] libds_srcs += libds_wayland_srcs -- 2.7.4 From 942b2a4c077056ca7fd75e131eefcd8dc55f9337 Mon Sep 17 00:00:00 2001 From: Duna Oh Date: Fri, 28 Aug 2020 15:33:51 +0900 Subject: [PATCH 14/16] DSTraceInfo: print out windows' infomation(pid,title,,etc.) Change-Id: Ib786d3b9139b41bbe93eec8faba071c76d749800 --- samples/exampleCompositor.cpp | 5 ++ src/DSTraceInfo/DSTraceInfo.cpp | 118 ++++++++++++++++++++++++++++++++++++++++ src/DSTraceInfo/DSTraceInfo.h | 62 +++++++++++++++++++++ src/meson.build | 3 + 4 files changed, 188 insertions(+) create mode 100644 src/DSTraceInfo/DSTraceInfo.cpp create mode 100644 src/DSTraceInfo/DSTraceInfo.h diff --git a/samples/exampleCompositor.cpp b/samples/exampleCompositor.cpp index 27787f5..a7b23a2 100644 --- a/samples/exampleCompositor.cpp +++ b/samples/exampleCompositor.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include "DSDebugLog.h" using namespace display_server; @@ -70,6 +71,9 @@ public: __textInput = std::make_shared(); + __traceInfo = std::make_shared(); + __traceInfo->attachPolicyArea(__policyArea); + return __canvas; } @@ -103,6 +107,7 @@ private: std::shared_ptr __policyArea; std::shared_ptr __displayArea; std::shared_ptr __textInput; + std::shared_ptr __traceInfo; }; int main() { diff --git a/src/DSTraceInfo/DSTraceInfo.cpp b/src/DSTraceInfo/DSTraceInfo.cpp new file mode 100644 index 0000000..608c562 --- /dev/null +++ b/src/DSTraceInfo/DSTraceInfo.cpp @@ -0,0 +1,118 @@ +/* +* Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#include "DSTraceInfo.h" +#include "DSPolicyAreaPrivate.h" + +namespace display_server +{ +DSTraceInfo::DSTraceInfo() + : __policyArea(nullptr), + __zone(nullptr), + __eventLoop(nullptr), + __windowUpdated(false) +{ + __eventLoop = DSEventLoop::getInstance(); + if (__eventLoop) + __eventLoop->registerCallbackIdleEnterer(this, std::bind(&DSTraceInfo::__onEventIdleEnterer, this, std::placeholders::_1)); +} + +DSTraceInfo::~DSTraceInfo() +{ + if (__eventLoop) + DSEventLoop::releaseInstance(); +} + +bool DSTraceInfo::attachPolicyArea(std::shared_ptr policyArea) +{ + __policyArea = policyArea; + + DSPolicyAreaPrivate *policyAreaPriv = DSPolicyAreaPrivate::getPrivate(__policyArea.get()); + __zone = policyAreaPriv->getZone(); + + if (__zone == nullptr) { + DSLOG_ERR("DSTraceInfo", "No zone attached to this policyArea(%p)", policyArea); + return false; + } + + __zone->registerCallbackWindowCreated(this, std::bind(&DSTraceInfo::__onWindowCreated, this, std::placeholders::_1)); + __zone->registerCallbackWindowStackChanged(this, std::bind(&DSTraceInfo::__onWindowStackChanged, this, std::placeholders::_1)); + __zone->registerCallbackWindowDestroy(this, std::bind(&DSTraceInfo::__onWindowDestroy, this, std::placeholders::_1)); + + __windowList = __zone->getWindowList(); + + return true; +} + +void DSTraceInfo::__onEventIdleEnterer(void *data) +{ + if (__windowUpdated) + { + printWindowsInfo(); + __windowUpdated = false; + } +} + +void DSTraceInfo::printWindowsInfo() +{ + DSLOG_INF("DSTraceInfo", "--------------Top level windows: %d--------------", __windowList.size()); + DSLOG_INF("DSTraceInfo", " No Win_ID PID w h x y (S)kipFoc has(F)ocus (U)serGeom (V)kbdFloating Parent Title"); + + for (std::shared_ptr w : __windowList) + { + stPosition pos = w->getPosition(); + stSize sz = w->getSize(); + DSWaylandSurface *dwlSurface = w->surface(); + DSWaylandClient *dwClient = dwlSurface->getClient(); + pid_t pid = dwClient->pid(); + DSLOG_INF("DSTraceInfo", " %d: %p %d %4d %4d %4d %4d %c %c %c %c %p %s", w->getZOrder(), w.get(), pid, \ + sz.w, sz.h, pos.x, pos.y, w->getSkipFocus()?'S':' ', w->hasFocus()?'F':' ', w->isAllowUserGeometry()?'U':' ', w->getVkbdFloating()?'V':' ', \ + w->getParent(), (w->getTitle().compare("") == 0)?"No Title":w->getTitle().c_str()); + } + + DSLOG_INF("DSTraceInfo", "------------------------------------------------"); +} + +void DSTraceInfo::__onWindowCreated(std::shared_ptr window) +{ + __windowList.remove(window); + __windowList.push_front(window); + + __windowUpdated = true; +} + +void DSTraceInfo::__onWindowStackChanged(std::shared_ptr window) +{ + __windowList = __zone->getWindowList(); + + __windowUpdated = true; +} + +void DSTraceInfo::__onWindowDestroy(std::shared_ptr window) +{ + __windowList.remove(window); + + __windowUpdated = true; +} + +} \ No newline at end of file diff --git a/src/DSTraceInfo/DSTraceInfo.h b/src/DSTraceInfo/DSTraceInfo.h new file mode 100644 index 0000000..35a6516 --- /dev/null +++ b/src/DSTraceInfo/DSTraceInfo.h @@ -0,0 +1,62 @@ +/* +* Copyright © 2020 Samsung Electronics co., Ltd. All Rights Reserved. +* +* Permission is hereby granted, free of charge, to any person obtaining a +* copy of this software and associated documentation files (the "Software"), +* to deal in the Software without restriction, including without limitation +* the rights to use, copy, modify, merge, publish, distribute, sublicense, +* and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice (including the next +* paragraph) shall be included in all copies or substantial portions of the +* Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +* DEALINGS IN THE SOFTWARE. +*/ + +#ifndef __DS_TRACE_INFO_H__ +#define __DS_TRACE_INFO_H__ + +#include +#include "DSSignal.h" +#include "DSWindow.h" +#include "DSPolicyArea.h" +#include "DSZone.h" +#include "DSEventLoop.h" + +namespace display_server +{ + +class DSTraceInfo : public DSObject +{ +public: + explicit DSTraceInfo(); + virtual ~DSTraceInfo(); + bool attachPolicyArea(std::shared_ptr policyArea); + void printWindowsInfo(); + +private: + void __onWindowCreated(std::shared_ptr window); + void __onWindowStackChanged(std::shared_ptr window); + void __onWindowDestroy(std::shared_ptr window); + + void __onEventIdleEnterer(void *data); + + std::shared_ptr __policyArea; + std::shared_ptr __zone; + std::list> __windowList; + + DSEventLoop *__eventLoop; + bool __windowUpdated; +}; + +} + +#endif \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index 62c7b30..9facc3c 100644 --- a/src/meson.build +++ b/src/meson.build @@ -78,6 +78,8 @@ libds_srcs = [ 'DSTextInput/DSTextInput.cpp', 'DSUtil/DSUtilSocket.h', 'DSUtil/DSUtilSocket.cpp', + 'DSTraceInfo/DSTraceInfo.h', + 'DSTraceInfo/DSTraceInfo.cpp', ] libds_wayland_srcs = [ @@ -255,6 +257,7 @@ libds_include_dirs = include_directories( './DSTextInput', './DSTizenAppinfo', './DSUtil', + './DSTraceInfo', ) libds_lib = shared_library( -- 2.7.4 From 53b4e1a5841269d1ad647689e1d2660c4150cc1b Mon Sep 17 00:00:00 2001 From: jeon Date: Fri, 28 Aug 2020 16:50:55 +0900 Subject: [PATCH 15/16] DSTextInput: Add a TextInput API to get current TextInput window Change-Id: If73ce8395a909588e1fbd4df39303fceb21b582a --- src/DSTextInput/DSTextInput.cpp | 5 ++++ src/DSTextInput/DSTextInputPrivate.h | 1 + src/DSWaylandServer/DSWaylandInputPanel.cpp | 29 ++++++++++++++++++++-- src/DSWaylandServer/DSWaylandInputPanel.h | 1 + .../DSWaylandInputPanelSurfacePrivate.h | 1 + src/DSWaylandServer/DSWaylandTextInput.cpp | 15 ++++++++++- src/DSWaylandServer/DSWaylandTextInput.h | 2 ++ src/DSWaylandServer/DSWaylandTextInputManager.h | 2 ++ src/DSWaylandServer/DSWaylandTextInputPrivate.h | 2 +- tests/DSWaylandInputPanel-test.cpp | 12 +++++++++ tests/DSWaylandTextInput-test.cpp | 14 +++++++++++ tests/DSWaylandTextInputManager-test.cpp | 12 +++++++++ 12 files changed, 92 insertions(+), 4 deletions(-) diff --git a/src/DSTextInput/DSTextInput.cpp b/src/DSTextInput/DSTextInput.cpp index 83e4eb7..9f61c9a 100644 --- a/src/DSTextInput/DSTextInput.cpp +++ b/src/DSTextInput/DSTextInput.cpp @@ -174,6 +174,11 @@ void DSTextInputPrivate::setGeometryUpdated(bool updated) __wlTextInputManager->setGeometryUpdated(updated); } +DSWaylandSurface *DSTextInputPrivate::getTextInputSurface() +{ + return __wlTextInputManager->getTextInputSurface(); +} + void DSTextInputPrivate::contextCommitString(unsigned int serial, std::string text) { diff --git a/src/DSTextInput/DSTextInputPrivate.h b/src/DSTextInput/DSTextInputPrivate.h index ae1199a..d99726a 100644 --- a/src/DSTextInput/DSTextInputPrivate.h +++ b/src/DSTextInput/DSTextInputPrivate.h @@ -83,6 +83,7 @@ public: void predictionHintData(std::string key, std::string value); void updateTextInputPanelState(bool state); void setGeometryUpdated(bool updated); + DSWaylandSurface *getTextInputSurface(); /* DSWaylandInputMethodContext request */ void contextCommitString(unsigned int serial, std::string text); diff --git a/src/DSWaylandServer/DSWaylandInputPanel.cpp b/src/DSWaylandServer/DSWaylandInputPanel.cpp index 51ef817..77c65a0 100644 --- a/src/DSWaylandServer/DSWaylandInputPanel.cpp +++ b/src/DSWaylandServer/DSWaylandInputPanel.cpp @@ -256,6 +256,13 @@ void DSWaylandInputPanel::updateTextInputPanelState(bool state) __dsTextInputPrivate->updateTextInputPanelState(state); } +DSWaylandSurface *DSWaylandInputPanel::getTextInputSurface() +{ + if (!__dsTextInputPrivate) return nullptr; + + return __dsTextInputPrivate->getTextInputSurface(); +} + void DSWaylandInputPanel::__onEventIdleEnterer(void *data) { } @@ -274,8 +281,7 @@ DSWaylandInputPanelSurfacePrivate::~DSWaylandInputPanelSurfacePrivate() void DSWaylandInputPanelSurfacePrivate::createGlobal(void *client, void *inputPanelResource, unsigned int id, void *surface) { Resource *resource = add((struct ::wl_client *)client, id, 1); - DSWaylandInputPanelSurfaceData *data = new DSWaylandInputPanelSurfaceData(resource, inputPanelResource, surface); - __dataMap.insert(std::pair(resource, data)); + __appendSurface(resource, inputPanelResource, surface); } void DSWaylandInputPanelSurfacePrivate::clearGlobals(void *inputPanelResource) @@ -571,6 +577,25 @@ void DSWaylandInputPanelSurfacePrivate::__updateSurfaceVisibility(DSWaylandInput } } +void DSWaylandInputPanelSurfacePrivate::__appendSurface(Resource *resource, void *inputPanelResource, void *surface) +{ + DS_GET_PUB(DSWaylandInputPanelSurface); + DSWaylandInputPanelSurfaceData *data = new DSWaylandInputPanelSurfaceData(resource, inputPanelResource, surface); + __dataMap.insert(std::pair(resource, data)); + + DSWaylandSurface *textInputSurface = pub->__inputPanel->getTextInputSurface(); + + if (textInputSurface) + { + //TODO: transparent set + } + + if (pub->__inputPanel->getRerunPanelShow()) + { + pub->__inputPanel->changeVisibility(true); + } +} + DSWaylandInputPanelSurface::DSWaylandInputPanelSurface(DSWaylandCompositor *compositor, DSWaylandInputPanel *inputPanel) : DSObject(), _d_ptr(std::make_unique(this, compositor)), diff --git a/src/DSWaylandServer/DSWaylandInputPanel.h b/src/DSWaylandServer/DSWaylandInputPanel.h index 4217502..f456580 100644 --- a/src/DSWaylandServer/DSWaylandInputPanel.h +++ b/src/DSWaylandServer/DSWaylandInputPanel.h @@ -63,6 +63,7 @@ public: DSWaylandInputPanelFloating *getFloatingData(); stGeometry getSurfaceGeometry(DSWaylandSurface *wlSurface); void updateTextInputPanelState(bool state); + DSWaylandSurface *getTextInputSurface(); private: DSWaylandCompositor *__compositor; diff --git a/src/DSWaylandServer/DSWaylandInputPanelSurfacePrivate.h b/src/DSWaylandServer/DSWaylandInputPanelSurfacePrivate.h index 6644229..4896e3c 100644 --- a/src/DSWaylandServer/DSWaylandInputPanelSurfacePrivate.h +++ b/src/DSWaylandServer/DSWaylandInputPanelSurfacePrivate.h @@ -68,6 +68,7 @@ private: std::multimap __dataMap; void __updateSurfaceVisibility(DSWaylandInputPanelSurfaceData *surfaceData); + void __appendSurface(Resource *resource, void *inputPanelResource, void *surface); }; } diff --git a/src/DSWaylandServer/DSWaylandTextInput.cpp b/src/DSWaylandServer/DSWaylandTextInput.cpp index e062cb0..743d57c 100644 --- a/src/DSWaylandServer/DSWaylandTextInput.cpp +++ b/src/DSWaylandServer/DSWaylandTextInput.cpp @@ -25,6 +25,7 @@ #include "DSWaylandTextInputManagerPrivate.h" #include "DSWaylandTextInput.h" #include "DSWaylandTextInputPrivate.h" +#include "DSWaylandSurface.h" namespace display_server { @@ -203,6 +204,11 @@ void DSWaylandTextInputManager::setGeometryUpdated(bool updated) __textInput->setGeometryUpdated(updated); } +DSWaylandSurface* DSWaylandTextInputManager::getTextInputSurface() +{ + return __textInput->getClientSurface(); +} + DSWaylandTextInputPrivate::DSWaylandTextInputPrivate(DSWaylandTextInput *p_ptr, DSWaylandCompositor *compositor) : DSObjectPrivate(p_ptr), @@ -297,7 +303,7 @@ void DSWaylandTextInputPrivate::text_input_activate(Resource *resource, struct : pub->__dsTextInputPrivate->activateTextInput(pub, id); __activatedResource = resource; - __clientSurface = surface; + __clientSurface = DSWaylandSurface::fromWlResource(surface); } void DSWaylandTextInputPrivate::text_input_deactivate(Resource *resource, struct ::wl_resource *seat) @@ -1107,4 +1113,11 @@ void DSWaylandTextInput::setGeometryUpdated(bool updated) __geometryUpdated = updated; } +DSWaylandSurface* DSWaylandTextInput::getClientSurface() +{ + DS_GET_PRIV(DSWaylandTextInput); + + return priv->__clientSurface; +} + } diff --git a/src/DSWaylandServer/DSWaylandTextInput.h b/src/DSWaylandServer/DSWaylandTextInput.h index 7f56414..c6b738b 100644 --- a/src/DSWaylandServer/DSWaylandTextInput.h +++ b/src/DSWaylandServer/DSWaylandTextInput.h @@ -33,6 +33,7 @@ namespace display_server class DSWaylandTextInputPrivate; class DSTextInputPrivate; +class DSWaylandSurface; class DS_DECL_EXPORT DSWaylandTextInput : public DSObject { @@ -69,6 +70,7 @@ public: void updatePanelState(bool state); void setGeometryUpdated(bool updated); + DSWaylandSurface* getClientSurface(); protected: diff --git a/src/DSWaylandServer/DSWaylandTextInputManager.h b/src/DSWaylandServer/DSWaylandTextInputManager.h index 8523e10..c19519f 100644 --- a/src/DSWaylandServer/DSWaylandTextInputManager.h +++ b/src/DSWaylandServer/DSWaylandTextInputManager.h @@ -34,6 +34,7 @@ namespace display_server class DSWaylandTextInputManagerPrivate; class DSWaylandTextInput; +class DSWaylansSurface; class DS_DECL_EXPORT DSWaylandTextInputManager : public DSObject { @@ -71,6 +72,7 @@ public: void updateTextInputPanelState(bool state); void setGeometryUpdated(bool updated); + DSWaylandSurface* getTextInputSurface(); protected: diff --git a/src/DSWaylandServer/DSWaylandTextInputPrivate.h b/src/DSWaylandServer/DSWaylandTextInputPrivate.h index bf9ef9d..55fb499 100644 --- a/src/DSWaylandServer/DSWaylandTextInputPrivate.h +++ b/src/DSWaylandServer/DSWaylandTextInputPrivate.h @@ -103,7 +103,7 @@ private: std::multimap __resourceIdMap; struct ::wl_client *__showClient; Resource *__activatedResource; - struct ::wl_resource *__clientSurface; + DSWaylandSurface *__clientSurface; }; } diff --git a/tests/DSWaylandInputPanel-test.cpp b/tests/DSWaylandInputPanel-test.cpp index 7e9b421..04d72a2 100644 --- a/tests/DSWaylandInputPanel-test.cpp +++ b/tests/DSWaylandInputPanel-test.cpp @@ -204,3 +204,15 @@ TEST_F(DSWaylandInputPanelTest, UpdateTextInputPanelState) DSWaylandCompositor::releaseInstance(); } +TEST_F(DSWaylandInputPanelTest, GetTextInputSurface) +{ + DSWaylandCompositor *comp = DSWaylandCompositor::getInstance(); + DSWaylandInputPanel *inputPanel = new DSWaylandInputPanel(comp); + EXPECT_TRUE(inputPanel != nullptr); + + (void)inputPanel->getTextInputSurface(); + + delete inputPanel; + DSWaylandCompositor::releaseInstance(); +} + diff --git a/tests/DSWaylandTextInput-test.cpp b/tests/DSWaylandTextInput-test.cpp index 0befd84..5a3e18e 100644 --- a/tests/DSWaylandTextInput-test.cpp +++ b/tests/DSWaylandTextInput-test.cpp @@ -389,3 +389,17 @@ TEST_F(DSWaylandTextInputTest, SetGeometryUpdated) DSWaylandCompositor::releaseInstance(); } +TEST_F(DSWaylandTextInputTest, GetClientSurface) +{ + DSWaylandCompositor *comp = DSWaylandCompositor::getInstance(); + DSWaylandTextInputManager *textInputManager = new DSWaylandTextInputManager(comp); + DSWaylandTextInput *textInput = new DSWaylandTextInput(comp, textInputManager); + EXPECT_TRUE(textInput != nullptr); + + (void)textInput->getClientSurface(); + + delete textInput; + delete textInputManager; + DSWaylandCompositor::releaseInstance(); +} + diff --git a/tests/DSWaylandTextInputManager-test.cpp b/tests/DSWaylandTextInputManager-test.cpp index 4f74e7f..abca02b 100644 --- a/tests/DSWaylandTextInputManager-test.cpp +++ b/tests/DSWaylandTextInputManager-test.cpp @@ -338,3 +338,15 @@ TEST_F(DSWaylandTextInputManagerTest, SetGeometryUpdated) DSWaylandCompositor::releaseInstance(); } +TEST_F(DSWaylandTextInputManagerTest, GetTextInputSurface) +{ + DSWaylandCompositor *comp = DSWaylandCompositor::getInstance(); + DSWaylandTextInputManager *textInputManager = new DSWaylandTextInputManager(comp); + EXPECT_TRUE(textInputManager != nullptr); + + (void)textInputManager->getTextInputSurface(); + + delete textInputManager; + DSWaylandCompositor::releaseInstance(); +} + -- 2.7.4 From 825c66e075bbcf2029ee396c1191a1d10ce03ac0 Mon Sep 17 00:00:00 2001 From: SooChan Lim Date: Fri, 28 Aug 2020 16:43:33 +0900 Subject: [PATCH 16/16] DsRenderView: add raiseToTop, lowerToBottom and setPosition methods Change-Id: I6b2c11f9c1b3f31de6d531cac2389a1f0e7aa3c5 --- src/DSRender/DSRenderView.h | 3 +++ src/DSRender/DSRenderViewDaliImpl.cpp | 30 ++++++++++++++++++++++++++++++ src/DSRender/DSRenderViewDaliImpl.h | 3 +++ src/DSRender/DSRenderViewEcoreEvasImpl.cpp | 15 +++++++++++++++ src/DSRender/DSRenderViewEcoreEvasImpl.h | 3 +++ 5 files changed, 54 insertions(+) diff --git a/src/DSRender/DSRenderView.h b/src/DSRender/DSRenderView.h index e5c85b4..e67a05a 100644 --- a/src/DSRender/DSRenderView.h +++ b/src/DSRender/DSRenderView.h @@ -40,6 +40,9 @@ public: virtual bool setBuffer(std::shared_ptr buffer) = 0; virtual std::shared_ptr getWindow() = 0; + virtual void raiseToTop() = 0; + virtual void lowerToBottom() = 0; + virtual void setPosition(int x, int y) = 0; virtual void registerCallbackUpdated(DSObject *slot, std::function func) = 0; private: diff --git a/src/DSRender/DSRenderViewDaliImpl.cpp b/src/DSRender/DSRenderViewDaliImpl.cpp index a72214f..18ec7e7 100644 --- a/src/DSRender/DSRenderViewDaliImpl.cpp +++ b/src/DSRender/DSRenderViewDaliImpl.cpp @@ -162,6 +162,36 @@ void DSRenderViewDaliImpl::registerCallbackUpdated(DSObject *slot, std::function __updatedSignal.connect(slot, func); } +void DSRenderViewDaliImpl::raiseToTop() +{ + DSLOG_INF("DSRenderViewDaliImpl", ""); + + __textureViewActor.SetProperty(Actor::Property::VISIBLE, true); + __textureViewActor.RaiseToTop(); + + __updatedSignal.emit(nullptr); +} + +void DSRenderViewDaliImpl::lowerToBottom() +{ + DSLOG_INF("DSRenderViewDaliImpl", ""); + + __textureViewActor.SetProperty(Actor::Property::VISIBLE, true); + __textureViewActor.LowerToBottom(); + + __updatedSignal.emit(nullptr); +} + +void DSRenderViewDaliImpl::setPosition(int x, int y) +{ + DSLOG_INF("DSRenderViewDaliImpl", ""); + + __textureViewActor.SetProperty(Actor::Property::VISIBLE, true); + __textureViewActor.SetProperty(Actor::Property::POSITION, Vector3(x, y, 0.0f)); + + __updatedSignal.emit(nullptr); +} + void DSRenderViewDaliImpl::__onWindowBufferChanged(std::shared_ptr buffer) { if (buffer) { diff --git a/src/DSRender/DSRenderViewDaliImpl.h b/src/DSRender/DSRenderViewDaliImpl.h index 8ffd858..6a0c252 100644 --- a/src/DSRender/DSRenderViewDaliImpl.h +++ b/src/DSRender/DSRenderViewDaliImpl.h @@ -42,6 +42,9 @@ public: bool setBuffer(std::shared_ptr buffer) override; std::shared_ptr getWindow() override; + void raiseToTop() override; + void lowerToBottom() override; + void setPosition(int x, int y) override; void registerCallbackUpdated(DSObject *slot, std::function func) override; diff --git a/src/DSRender/DSRenderViewEcoreEvasImpl.cpp b/src/DSRender/DSRenderViewEcoreEvasImpl.cpp index 9fe237d..d97e3e7 100644 --- a/src/DSRender/DSRenderViewEcoreEvasImpl.cpp +++ b/src/DSRender/DSRenderViewEcoreEvasImpl.cpp @@ -78,6 +78,21 @@ std::shared_ptr DSRenderViewEcoreEvasImpl::getWindow() return __window; } +void DSRenderViewEcoreEvasImpl::raiseToTop() +{ + //TODO: +} + +void DSRenderViewEcoreEvasImpl::lowerToBottom() +{ + //TODO: +} + +void DSRenderViewEcoreEvasImpl::setPosition(int x, int y) +{ + //TODO: +} + void DSRenderViewEcoreEvasImpl::registerCallbackUpdated(DSObject *slot, std::function func) { // No updated signal at ecore evas implementation yet. diff --git a/src/DSRender/DSRenderViewEcoreEvasImpl.h b/src/DSRender/DSRenderViewEcoreEvasImpl.h index 0572a19..18d1eff 100644 --- a/src/DSRender/DSRenderViewEcoreEvasImpl.h +++ b/src/DSRender/DSRenderViewEcoreEvasImpl.h @@ -39,6 +39,9 @@ public: bool setBuffer(std::shared_ptr buffer) override; std::shared_ptr getWindow() override; + void raiseToTop() override; + void lowerToBottom() override; + void setPosition(int x, int y) override; void registerCallbackUpdated(DSObject *slot, std::function func) override; -- 2.7.4