DSWaylandProtocolTrace::DSWaylandProtocolTrace(DSObject *parent)
: DS_INIT_PRIVATE_PTR(DSWaylandProtocolTrace)
{
- //init();
- DS_GET_PRIV(DSWaylandProtocolTrace);
- priv->__wlCompositor = DSWaylandCompositor::getInstance();
}
DSWaylandProtocolTrace::~DSWaylandProtocolTrace()
DS_GET_PRIV(DSWaylandProtocolTrace);
bool ret = false;
char *env_path = nullptr;
- char tmp[PATH_MAX] = {0,};
rc = priv->rulechecker_init();
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;
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;
}
DSWaylandProtocolTracePrivate::DSWaylandProtocolTracePrivate(DSWaylandProtocolTrace *p_ptr)
: DSObjectPrivate(p_ptr), __p_ptr(p_ptr)
{
-
+ __wlCompositor = DSWaylandCompositor::getInstance();
}
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);
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");
}
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");
}
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);
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");
fd = open(filename, O_RDONLY);
if(fd<0)
{
- DSLOG_DBG("DSWaylandProtocolTracePriv", "failed: open '%s'", filename);
+ DSLOG_ERR("DSWaylandProtocolTracePriv", "failed: open '%s'", filename);
return false;
}
DSLOG_INF("DSWaylandProtocolTracePriv", "%s", strbuf);
wl_list_remove(&listener->link);
- //free(listener);
- delete listener;
+ free(listener);
listener = nullptr;
}
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);
{
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;
{
ProtocolTrace_Tree *tree = (ProtocolTrace_Tree *)calloc(1, sizeof(ProtocolTrace_Tree) + size);
// eina safety
+ if(!tree)
+ return nullptr;
tree->size = size;
tree->head = nullptr;
{
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)
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)
goto fail;
node = bintree_create_node(tree);
- //eina safty
+ //eina safety
data = (ProtocolTrace_Rule_Node *) bintree_get_node_data(node);
parser_token_process(token);
return node;
+
fail:
if(node)
bintree_remove_node_recursive(node);
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()
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;
}
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);
}
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;