Stackdb
Stackdb is a stackable, multi-target and -level source debugger and memory forensics library.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
target_nv_filter.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2013 The University of Utah
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
17  */
18 
19 #include <ctype.h>
20 #include <regex.h>
21 
22 #include "log.h"
23 #include "target_api.h"
24 #include "target.h"
25 #include "glib_wrapper.h"
26 
28  if (tfr->value_name)
29  free(tfr->value_name);
30  regfree(&tfr->regex);
31  free(tfr);
32 }
33 
35  GSList *gsltmp;
36  struct target_nv_filter_regex *tfr;
37 
38  v_g_slist_foreach(tf->value_regex_list,gsltmp,tfr) {
40  }
41  g_slist_free(tf->value_regex_list);
42  free(tf);
43 }
44 
45 /*
46  * Just parse name/value pairs.
47  */
49  struct target_nv_filter *tf;
50  struct target_nv_filter_regex *tfr;
51  GSList *gsltmp;
52  int isescaped;
53  char *cur;
54  char *str;
55 
56  expr = strdup(expr);
57 
58  tf = calloc(1,sizeof(*tf));
59 
60  cur = expr;
61  while (*cur != '\0') {
62  tfr = calloc(1,sizeof(*tfr));
63  /*
64  * Read: <identifier>, \s+, '=', \s+, '/', <regex>, '/'
65  */
66  while (*cur != '\0' && isspace(*cur))
67  ++cur;
68  str = cur;
69  while (*cur != '\0' && (isalnum(*cur) || *cur == '_'))
70  ++cur;
71  while (*cur != '\0' && isspace(*cur)) {
72  *cur = '\0';
73  ++cur;
74  }
75  if (*cur == '=') {
76  *cur = '\0';
77  ++cur;
78  }
79  else
80  goto errout;
81  tfr->value_name = strdup(str);
82  while (*cur != '\0' && isspace(*cur))
83  ++cur;
84  if (*cur == '/') {
85  ++cur;
86  str = cur;
87  }
88  else
89  goto errout;
90  isescaped = 0;
91  while (*cur != '\0') {
92  if (*cur == '\\') {
93  if (!isescaped)
94  isescaped = 1;
95  else
96  isescaped = 0;
97  }
98  else if (*cur == '/' && !isescaped)
99  break;
100  else
101  isescaped = 0;
102  ++cur;
103  }
104  if (*cur == '/') {
105  *cur = '\0';
106  if (regcomp(&tfr->regex,str,REG_EXTENDED | REG_NOSUB))
107  goto errout;
108  ++cur;
109  }
110 
111  tf->value_regex_list = g_slist_append(tf->value_regex_list,tfr);
112 
113  while (*cur != '\0' && isspace(*cur))
114  ++cur;
115 
116  if (*cur == ',')
117  ++cur;
118  }
119 
120  free(expr);
121 
122  return tf;
123 
124  errout:
125  if (tfr)
127  v_g_slist_foreach(tf->value_regex_list,gsltmp,tfr) {
129  }
130  g_slist_free(tf->value_regex_list);
131  free(tf);
132  free(expr);
133  return NULL;
134 }
struct target_nv_filter * target_nv_filter_parse(char *expr)
void target_nv_filter_regex_free(struct target_nv_filter_regex *tfr)
#define v_g_slist_foreach(gslhead, gslcur, elm)
Definition: glib_wrapper.h:60
void free(void *ptr)
Definition: debugserver.c:207
GSList * value_regex_list
Definition: target.h:685
void * calloc(size_t nmemb, size_t size)
Definition: debugserver.c:200
void target_nv_filter_free(struct target_nv_filter *tf)