1 /**************************************************************************
5 Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
7 Contact: Boram Park <boram1288.park@samsung.com>
8 Sangjin LEE <lsj119@samsung.com>
10 Permission is hereby granted, free of charge, to any person obtaining a
11 copy of this software and associated documentation files (the
12 "Software"), to deal in the Software without restriction, including
13 without limitation the rights to use, copy, modify, merge, publish,
14 distribute, sub license, and/or sell copies of the Software, and to
15 permit persons to whom the Software is furnished to do so, subject to
16 the following conditions:
18 The above copyright notice and this permission notice (including the
19 next paragraph) shall be included in all copies or substantial portions
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
25 IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR
26 ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
27 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
28 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 **************************************************************************/
35 #include <sys/types.h>
36 #include <sys/fcntl.h>
44 #include "xdbg_types.h"
45 #include "xdbg_evlog.h"
46 #include "bool_exp_rule_checker.h"
48 static char *evt_type[] = { "Event", "Request", "Reply", "Flush" };
49 static char *evt_dir[] = { "<====", "---->", "<----", "*****" };
51 static RULE_CHECKER rc = NULL;
54 _mergeArgs (char * target, int argc, const char ** argv)
59 for (i=0; i<argc; i++)
61 len = sprintf (target, "%s", argv[i]);
70 _strcasecmp(const char *str1, const char *str2)
72 const u_char *us1 = (const u_char *) str1, *us2 = (const u_char *) str2;
74 while (tolower(*us1) == tolower(*us2)) {
80 return (tolower(*us1) - tolower(*us2));
84 xDbgEvlogGetCmd (char *path)
89 p = strrchr (path, '/');
94 xDbgEvlogRuleSet (const int argc, const char **argv, char *reply, int *len)
99 rc = rulechecker_init();
103 rulechecker_print_rule (rc, reply);
109 if (!_strcasecmp (command, "add"))
111 POLICY_TYPE policy_type;
112 RC_RESULT_TYPE result;
113 const char * policy = argv[1];
118 REPLY ("Error : Too few arguments.\n");
122 if (!_strcasecmp (policy, "ALLOW"))
124 else if (!_strcasecmp (policy, "DENY"))
128 REPLY ("Error : Unknown policy : [%s].\n Policy should be ALLOW or DENY.\n", policy);
132 _mergeArgs (rule, argc - 2, &(argv[2]));
134 result = rulechecker_add_rule (rc, policy_type, rule);
135 if (result == RC_ERR_TOO_MANY_RULES)
137 REPLY ("Error : Too many rules were added.\n");
140 else if (result == RC_ERR_PARSE_ERROR)
142 REPLY ("Error : An error occured during parsing the rule [%s]\n", rule);
146 REPLY ("The rule was successfully added.\n\n");
147 rulechecker_print_rule (rc, reply);
150 else if (!_strcasecmp (command, "remove"))
152 const char * remove_idx;
157 REPLY ("Error : Too few arguments.\n");
161 for (i=0; i<argc - 1; i++)
163 remove_idx = argv[i+1];
165 if (!_strcasecmp (remove_idx, "all"))
167 rulechecker_destroy (rc);
168 rc = rulechecker_init();
169 REPLY ("Every rules were successfully removed.\n");
173 int index = atoi (remove_idx);
174 if (isdigit (*remove_idx) && rulechecker_remove_rule (rc, index) == 0)
175 REPLY ("The rule [%d] was successfully removed.\n", index);
177 REPLY ("Rule remove fail : No such rule [%s].\n", remove_idx);
180 rulechecker_print_rule (rc, reply);
183 else if (!_strcasecmp (command, "print"))
185 rulechecker_print_rule (rc, reply);
188 else if (!_strcasecmp (command, "help"))
190 REPLY ("%s", rulechecker_print_usage());
194 REPLY ("%s\nUnknown command : [%s].\n\n", rulechecker_print_usage(), command);
200 xDbgEvlogRuleValidate (EvlogInfo *evinfo)
202 const char *evlog_name = "";
206 rc = rulechecker_init ();
210 fprintf (stderr, "failed: create rulechecker\n");
214 cmd = xDbgEvlogGetCmd (evinfo->client.command);
216 if (evinfo->type == REQUEST)
217 evlog_name = evinfo->req.name;
218 else if (evinfo->type == EVENT)
219 evlog_name = evinfo->evt.name;
221 return rulechecker_validate_rule (rc,
230 ExtensionInfo Evlog_extensions[] = {
231 {xDbgEvlogCompositeGetBase, 0, 0, 0, NULL},
232 {xDbgEvlogDamageGetBase, 0, 0, 0, NULL},
233 {xDbgEvlogDri2GetBase, 0, 0, 0, NULL},
234 {xDbgEvlogGestureGetBase, 0, 0, 0, NULL},
235 {xDbgEvlogRandrGetBase, 0, 0, 0, NULL},
236 {xDbgEvlogXextDpmsGetBase, 0, 0, 0, NULL},
237 {xDbgEvlogXextShmGetBase, 0, 0, 0, NULL},
238 {xDbgEvlogXextSyncGetBase, 0, 0, 0, NULL},
239 {xDbgEvlogXextXtestGetBase, 0, 0, 0, NULL},
240 {xDbgEvlogXextXtestExt1GetBase, 0, 0, 0, NULL},
241 {xDbgEvlogXvGetBase, 0, 0, 0, NULL}
243 ExtensionInfo* Sorted_Evlog_extensions;
246 _ExtensionsSwap(ExtensionInfo* first, ExtensionInfo* second)
256 _SortEvlogExtensions ()
261 Sorted_Evlog_extensions = (ExtensionInfo*)malloc(sizeof(Evlog_extensions));
262 RETURN_VAL_IF_FAIL (Sorted_Evlog_extensions != NULL, FALSE);
264 memcpy(Sorted_Evlog_extensions, Evlog_extensions, sizeof(Evlog_extensions));
266 for (i = 0 ; i < sizeof (Evlog_extensions) / sizeof (ExtensionInfo) - 1 ; i++)
269 for (j = 1 ; j < sizeof (Evlog_extensions) / sizeof (ExtensionInfo) - i ; j++)
271 if(Sorted_Evlog_extensions[j-1].evt_base > Sorted_Evlog_extensions[j].evt_base)
273 _ExtensionsSwap(&Sorted_Evlog_extensions[j-1], &Sorted_Evlog_extensions[j]);
285 _EvlogGetExtentionEntry (int *return_extensions_size)
288 static Bool success = FALSE;
298 dpy = XOpenDisplay (NULL);
301 fprintf (stderr, "failed: open display\n");
306 for (i = 0 ; i < sizeof (Evlog_extensions) / sizeof (ExtensionInfo); i++)
308 Evlog_extensions[i].get_base_func (dpy, Evlog_extensions + i);
311 if(!_SortEvlogExtensions ())
318 *return_extensions_size = sizeof(Evlog_extensions);
326 xDbgEvlogFillLog (EvlogInfo *evinfo, char *reply, int *len)
329 static int Extensions_size = 0;
331 RETURN_IF_FAIL (evinfo->type >= 0 && (sizeof (evt_dir) / sizeof (char*)));
332 RETURN_IF_FAIL (evinfo->type >= 0 && (sizeof (evt_type) / sizeof (char*)));
334 REPLY ("[%10.3f][%5ld] %22s(%2d:%5d) %s %s",
335 evinfo->time / 1000.0,
337 xDbgEvlogGetCmd (evinfo->client.command),
338 evinfo->client.index,
340 evt_dir[evinfo->type],
341 evt_type[evinfo->type]);
343 if (evinfo->type == REQUEST && _EvlogGetExtentionEntry (&Extensions_size))
346 reply = xDbgEvlogReqeust (evinfo, Extensions_size, reply, len);
349 else if (evinfo->type == EVENT && _EvlogGetExtentionEntry (&Extensions_size))
352 reply = xDbgEvlogEvent (evinfo, Extensions_size, reply, len);
357 const char *evlog_name = "";
358 if (evinfo->type == REQUEST)
359 evlog_name = evinfo->req.name;
360 else if (evinfo->type == EVENT)
361 evlog_name = evinfo->evt.name;
362 REPLY ("(%s)", evlog_name);