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>
43 #include "xdbg_types.h"
44 #include "xdbg_evlog.h"
45 #include "bool_exp_rule_checker.h"
47 static char *evt_type[] = { "Event", "Request", "Reply", "Flush" };
48 static char *evt_dir[] = { "<====", "---->", "<----", "*****" };
50 static RULE_CHECKER rc = NULL;
53 _mergeArgs (char * target, int argc, const char ** argv)
58 for (i=0; i<argc; i++)
60 len = sprintf (target, "%s", argv[i]);
69 _strcasecmp(const char *str1, const char *str2)
71 const u_char *us1 = (const u_char *) str1, *us2 = (const u_char *) str2;
73 while (tolower(*us1) == tolower(*us2)) {
79 return (tolower(*us1) - tolower(*us2));
83 xDbgEvlogGetCmd (char *path)
88 p = strrchr (path, '/');
93 xDbgEvlogRuleSet (const int argc, const char **argv, char *reply, int *len)
98 rc = rulechecker_init();
102 rulechecker_print_rule (rc, reply);
108 if (!_strcasecmp (command, "add"))
110 POLICY_TYPE policy_type;
111 RC_RESULT_TYPE result;
112 const char * policy = argv[1];
117 REPLY ("Error : Too few arguments.\n");
121 if (!_strcasecmp (policy, "ALLOW"))
123 else if (!_strcasecmp (policy, "DENY"))
127 REPLY ("Error : Unknown policy : [%s].\n Policy should be ALLOW or DENY.\n", policy);
131 _mergeArgs (rule, argc - 2, &(argv[2]));
133 result = rulechecker_add_rule (rc, policy_type, rule);
134 if (result == RC_ERR_TOO_MANY_RULES)
136 REPLY ("Error : Too many rules were added.\n");
139 else if (result == RC_ERR_PARSE_ERROR)
141 REPLY ("Error : An error occured during parsing the rule [%s]\n", rule);
145 REPLY ("The rule was successfully added.\n\n");
146 rulechecker_print_rule (rc, reply);
149 else if (!_strcasecmp (command, "remove"))
151 const char * remove_idx;
156 REPLY ("Error : Too few arguments.\n");
160 for (i=0; i<argc - 1; i++)
162 remove_idx = argv[i+1];
164 if (!_strcasecmp (remove_idx, "all"))
166 rulechecker_destroy (rc);
167 rc = rulechecker_init();
168 REPLY ("Every rules were successfully removed.\n");
172 int index = atoi (remove_idx);
173 if (isdigit (*remove_idx) && rulechecker_remove_rule (rc, index) == 0)
174 REPLY ("The rule [%d] was successfully removed.\n", index);
176 REPLY ("Rule remove fail : No such rule [%s].\n", remove_idx);
179 rulechecker_print_rule (rc, reply);
182 else if (!_strcasecmp (command, "print"))
184 rulechecker_print_rule (rc, reply);
187 else if (!_strcasecmp (command, "help"))
189 REPLY ("%s", rulechecker_print_usage());
193 REPLY ("%s\nUnknown command : [%s].\n\n", rulechecker_print_usage(), command);
199 xDbgEvlogRuleValidate (EvlogInfo *evinfo)
201 const char *evlog_name = "";
205 rc = rulechecker_init ();
209 fprintf (stderr, "failed: create rulechecker\n");
213 cmd = xDbgEvlogGetCmd (evinfo->client.command);
215 if (evinfo->type == REQUEST)
216 evlog_name = evinfo->req.name;
217 else if (evinfo->type == EVENT)
218 evlog_name = evinfo->evt.name;
220 return rulechecker_validate_rule (rc,
229 xDbgEvlogFillLog (EvlogInfo *evinfo, char *reply, int *len)
233 RETURN_IF_FAIL (evinfo->type >= 0 && (sizeof (evt_dir) / sizeof (char*)));
234 RETURN_IF_FAIL (evinfo->type >= 0 && (sizeof (evt_type) / sizeof (char*)));
236 REPLY ("[%10.3f][%5ld] %22s(%2d:%5d) %s %s",
237 evinfo->time / 1000.0,
239 xDbgEvlogGetCmd (evinfo->client.command),
240 evinfo->client.index,
242 evt_dir[evinfo->type],
243 evt_type[evinfo->type]);
245 if (evinfo->type == REQUEST)
248 reply = xDbgEvlogReqeust (evinfo, reply, len);
251 else if (evinfo->type == EVENT)
254 reply = xDbgEvlogEvent (evinfo, reply, len);
259 const char *evlog_name = "";
260 if (evinfo->type == REQUEST)
261 evlog_name = evinfo->req.name;
262 else if (evinfo->type == EVENT)
263 evlog_name = evinfo->evt.name;
264 REPLY ("(%s)", evlog_name);