2007-01-18 02:54:56 +00:00
|
|
|
/* dfilter-macro.c
|
|
|
|
*
|
2007-01-21 22:32:37 +00:00
|
|
|
* $Id$
|
2007-01-18 02:54:56 +00:00
|
|
|
*
|
|
|
|
* Wireshark - Network traffic analyzer
|
|
|
|
* By Gerald Combs <gerald@wireshark.org>
|
|
|
|
* Copyright 2001 Gerald Combs
|
2007-05-03 16:11:18 +00:00
|
|
|
*
|
2007-01-18 02:54:56 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2007-05-03 16:11:18 +00:00
|
|
|
*
|
2007-01-18 02:54:56 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
2007-05-03 16:11:18 +00:00
|
|
|
*
|
2007-01-18 02:54:56 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "dfilter-int.h"
|
|
|
|
#include "dfilter.h"
|
|
|
|
#include "dfilter-macro.h"
|
|
|
|
#include <epan/emem.h>
|
2007-01-29 04:57:23 +00:00
|
|
|
#include <epan/uat.h>
|
|
|
|
#include <epan/report_err.h>
|
2007-01-18 02:54:56 +00:00
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
static uat_t* dfilter_macro_uat = NULL;
|
|
|
|
static dfilter_macro_t* macros = NULL;
|
|
|
|
static guint num_macros;
|
2007-01-18 02:54:56 +00:00
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
void dfilter_macro_foreach(dfilter_macro_cb_t cb, void* data) {
|
|
|
|
guint i;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
for (i = 0; i < num_macros; i++) {
|
|
|
|
cb(&(macros[i]),data);
|
2007-01-18 02:54:56 +00:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void macro_fprint(dfilter_macro_t* m, void* ud) {
|
|
|
|
FILE* f = ud;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
fprintf(f,"%s\t%s\n",m->name,m->text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void dfilter_macro_save(const gchar* filename, gchar** error) {
|
|
|
|
FILE* f = fopen(filename,"w");
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
if (!f) {
|
|
|
|
*error = ep_strdup_printf("Could not open file: '%s', error: %s\n", filename, strerror(errno) );
|
|
|
|
return;
|
|
|
|
}
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
dfilter_macro_foreach(macro_fprint, f);
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
fclose(f);
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DUMP_MACROS
|
|
|
|
static void macro_dump(dfilter_macro_t* m _U_, void* ud _U_) {
|
|
|
|
gchar** part = m->parts;
|
|
|
|
int* args_pos = m->args_pos;
|
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
printf("\n->%s\t%s\t%d [%d]\n\t'%s'\n",
|
|
|
|
m->name, m->text, m->argc, m->usable, *(part++));
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
while (*part) {
|
|
|
|
printf("\t$%d '%s'\n",*args_pos,*part);
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
args_pos++;
|
|
|
|
part++;
|
|
|
|
}
|
|
|
|
}
|
2007-01-29 14:11:44 +00:00
|
|
|
#else
|
|
|
|
#define macro_dump(a,b)
|
2007-01-18 02:54:56 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
void dfilter_macro_dump(void) {
|
|
|
|
#ifdef DUMP_MACROS
|
|
|
|
dfilter_macro_foreach(macro_dump, NULL);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2007-04-23 10:59:26 +00:00
|
|
|
static gchar* dfilter_macro_resolve(gchar* name, gchar** args, const gchar** error) {
|
2007-01-18 02:54:56 +00:00
|
|
|
GString* text;
|
|
|
|
int argc = 0;
|
2007-01-29 04:57:23 +00:00
|
|
|
dfilter_macro_t* m = NULL;
|
2007-01-18 02:54:56 +00:00
|
|
|
int* arg_pos_p;
|
|
|
|
gchar** parts;
|
|
|
|
gchar* ret;
|
2007-01-29 04:57:23 +00:00
|
|
|
guint i;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
for (i = 0; i < num_macros; i++) {
|
|
|
|
dfilter_macro_t* c = &(macros[i]);
|
|
|
|
if ( c->usable && g_str_equal(c->name,name) ) {
|
|
|
|
m = c;
|
|
|
|
break;
|
|
|
|
}
|
2007-01-18 02:54:56 +00:00
|
|
|
}
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
if (!m) {
|
|
|
|
*error = ep_strdup_printf("macro '%s' does not exist", name);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
if (args) {
|
|
|
|
while(args[argc]) argc++;
|
|
|
|
}
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
if (argc != m->argc) {
|
|
|
|
*error = ep_strdup_printf("wrong number of arguments for macro '%s', expecting %d instead of %d",
|
|
|
|
name, m->argc, argc);
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
arg_pos_p = m->args_pos;
|
|
|
|
parts = m->parts;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
text = g_string_new(*(parts++));
|
2007-05-03 16:11:18 +00:00
|
|
|
|
|
|
|
if (args) {
|
|
|
|
while (*parts) {
|
|
|
|
g_string_sprintfa(text,"%s%s",
|
2007-01-18 02:54:56 +00:00
|
|
|
args[*(arg_pos_p++)],
|
|
|
|
*(parts++));
|
2007-05-03 16:11:18 +00:00
|
|
|
}
|
2007-01-18 02:54:56 +00:00
|
|
|
}
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
ret = ep_strdup(text->str);
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
g_string_free(text,TRUE);
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
return ret;
|
2007-01-18 02:54:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-23 10:59:26 +00:00
|
|
|
gchar* dfilter_macro_apply(const gchar* text, guint depth, const gchar** error) {
|
2007-01-18 02:54:56 +00:00
|
|
|
enum { OUTSIDE, STARTING, NAME, ARGS } state = OUTSIDE;
|
|
|
|
GString* out;
|
|
|
|
GString* name = NULL;
|
|
|
|
GString* arg = NULL;
|
|
|
|
GPtrArray* args = NULL;
|
|
|
|
gchar c;
|
|
|
|
const gchar* r = text;
|
|
|
|
gboolean changed = FALSE;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
if ( depth > 31) {
|
|
|
|
*error = "too much nesting in macros";
|
|
|
|
return NULL;
|
|
|
|
}
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
#define FGS(n) if (n) g_string_free(n,TRUE); n = NULL
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
#define FREE_ALL() \
|
|
|
|
do { \
|
|
|
|
FGS(name); \
|
|
|
|
FGS(arg); \
|
|
|
|
if (args) { \
|
|
|
|
while(args->len) { void* p = g_ptr_array_remove_index_fast(args,0); if (p) g_free(p); } \
|
|
|
|
g_ptr_array_free(args,TRUE); \
|
|
|
|
args = NULL; } } while(0)
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
*error = NULL;
|
|
|
|
out = g_string_sized_new(64);
|
|
|
|
|
|
|
|
while(1) {
|
|
|
|
c = *r++;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
switch(state) {
|
|
|
|
case OUTSIDE: {
|
|
|
|
switch(c) {
|
|
|
|
case '\0': {
|
|
|
|
goto finish;
|
|
|
|
} case '$': {
|
|
|
|
state = STARTING;
|
|
|
|
break;
|
|
|
|
} default: {
|
|
|
|
g_string_append_c(out,c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} case STARTING: {
|
|
|
|
switch (c) {
|
|
|
|
case '{': {
|
|
|
|
args = g_ptr_array_new();
|
|
|
|
arg = g_string_sized_new(32);
|
|
|
|
name = g_string_sized_new(32);
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
state = NAME;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
break;
|
|
|
|
} case '\0': {
|
|
|
|
g_string_append_c(out,'$');
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
goto finish;
|
|
|
|
} default: {
|
|
|
|
g_string_append_c(out,'$');
|
|
|
|
g_string_append_c(out,c);
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
state = OUTSIDE;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} case NAME: {
|
2007-04-13 23:32:21 +00:00
|
|
|
if ( isalnum((int)c) || c == '_' ) {
|
2007-01-18 02:54:56 +00:00
|
|
|
g_string_append_c(name,c);
|
|
|
|
} else if ( c == ':') {
|
|
|
|
state = ARGS;
|
|
|
|
} else if ( c == '}') {
|
|
|
|
gchar* resolved;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
g_ptr_array_add(args,NULL);
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
resolved = dfilter_macro_resolve(name->str, (gchar**)args->pdata, error);
|
|
|
|
if (*error) goto on_error;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
changed = TRUE;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
g_string_append(out,resolved);
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
FREE_ALL();
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
state = OUTSIDE;
|
|
|
|
} else if ( c == '\0') {
|
|
|
|
*error = "end of filter in the middle of a macro expression";
|
2007-05-03 16:11:18 +00:00
|
|
|
goto on_error;
|
2007-01-18 02:54:56 +00:00
|
|
|
} else {
|
|
|
|
*error = "invalid char in macro name";
|
|
|
|
goto on_error;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
} case ARGS: {
|
|
|
|
switch(c) {
|
|
|
|
case '\0': {
|
|
|
|
*error = "end of filter in the middle of a macro expression";
|
2007-05-03 16:11:18 +00:00
|
|
|
goto on_error;
|
2007-01-18 02:54:56 +00:00
|
|
|
} case ';': {
|
|
|
|
g_ptr_array_add(args,arg->str);
|
|
|
|
g_string_free(arg,FALSE);
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
arg = g_string_sized_new(32);
|
|
|
|
break;
|
|
|
|
} case '\\': {
|
|
|
|
c = *r++;
|
|
|
|
if (c) {
|
|
|
|
g_string_append_c(arg,c);
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
*error = "end of filter in the middle of a macro expression";
|
2007-05-03 16:11:18 +00:00
|
|
|
goto on_error;
|
2007-01-18 02:54:56 +00:00
|
|
|
}
|
|
|
|
} default: {
|
|
|
|
g_string_append_c(arg,c);
|
|
|
|
break;
|
|
|
|
} case '}': {
|
|
|
|
gchar* resolved;
|
|
|
|
g_ptr_array_add(args,arg->str);
|
|
|
|
g_ptr_array_add(args,NULL);
|
|
|
|
|
|
|
|
g_string_free(arg,FALSE);
|
|
|
|
arg = NULL;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
resolved = dfilter_macro_resolve(name->str, (gchar**)args->pdata, error);
|
|
|
|
if (*error) goto on_error;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
changed = TRUE;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
g_string_append(out,resolved);
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
FREE_ALL();
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
state = OUTSIDE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
finish:
|
|
|
|
{
|
|
|
|
FREE_ALL();
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-18 02:54:56 +00:00
|
|
|
if (changed) {
|
|
|
|
gchar* resolved = dfilter_macro_apply(out->str, depth++, error);
|
|
|
|
g_string_free(out,TRUE);
|
|
|
|
return (*error) ? NULL : resolved;
|
|
|
|
} else {
|
|
|
|
gchar* out_str = ep_strdup(out->str);
|
|
|
|
g_string_free(out,TRUE);
|
|
|
|
return out_str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
on_error:
|
|
|
|
{
|
|
|
|
FREE_ALL();
|
|
|
|
if (! *error) *error = "unknown error in macro expression";
|
|
|
|
g_string_free(out,TRUE);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2007-01-29 04:57:23 +00:00
|
|
|
|
2007-04-23 10:59:26 +00:00
|
|
|
static void macro_update(void* mp, const gchar** error) {
|
2007-01-29 04:57:23 +00:00
|
|
|
dfilter_macro_t* m = mp;
|
|
|
|
GPtrArray* parts;
|
|
|
|
GArray* args_pos;
|
|
|
|
const gchar* r;
|
|
|
|
gchar* w;
|
|
|
|
gchar* part;
|
|
|
|
int argc = 0;
|
|
|
|
guint i;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
*error = NULL;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
for (i = 0; i < num_macros; i++) {
|
|
|
|
if (m == &(macros[i])) continue;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
if ( g_str_equal(m->name,macros[i].name) ) {
|
|
|
|
*error = ep_strdup_printf("macro '%s' exists already", m->name);
|
|
|
|
m->usable = FALSE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
parts = g_ptr_array_new();
|
|
|
|
args_pos = g_array_new(FALSE,FALSE,sizeof(int));
|
|
|
|
|
|
|
|
m->priv = part = w = g_strdup(m->text);
|
|
|
|
r = m->text;
|
|
|
|
g_ptr_array_add(parts,part);
|
2007-05-03 16:11:18 +00:00
|
|
|
|
|
|
|
while (r && *r) {
|
|
|
|
|
|
|
|
switch (*r) {
|
2007-01-29 04:57:23 +00:00
|
|
|
default:
|
|
|
|
*(w++) = *(r++);
|
|
|
|
break;
|
|
|
|
case '\0':
|
|
|
|
*(w++) = *(r++);
|
|
|
|
goto done;
|
|
|
|
case '\\':
|
|
|
|
*(w++) = *(++r);
|
|
|
|
r++;
|
|
|
|
break;
|
|
|
|
case '$': {
|
|
|
|
int cnt = 0;
|
|
|
|
int arg_pos = 0;
|
|
|
|
do {
|
|
|
|
char c = *(r+1);
|
|
|
|
if (c >= '0' && c <= '9') {
|
|
|
|
cnt++;
|
|
|
|
r++;
|
|
|
|
arg_pos *= 10;
|
|
|
|
arg_pos += c - '0';
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
2007-05-03 16:11:18 +00:00
|
|
|
} while(*r);
|
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
if (cnt) {
|
|
|
|
*(w++) = '\0';
|
|
|
|
r++;
|
|
|
|
argc = argc < arg_pos ? arg_pos : argc;
|
|
|
|
arg_pos--;
|
|
|
|
g_array_append_val(args_pos,arg_pos);
|
|
|
|
g_ptr_array_add(parts,w);
|
|
|
|
} else {
|
|
|
|
*(w++) = *(r++);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-05-03 16:11:18 +00:00
|
|
|
|
|
|
|
}
|
2007-01-29 04:57:23 +00:00
|
|
|
|
|
|
|
done:
|
|
|
|
g_ptr_array_add(parts,NULL);
|
|
|
|
|
|
|
|
if (m->parts) g_free(m->parts);
|
|
|
|
|
|
|
|
m->parts = (gchar**)parts->pdata;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
if (m->args_pos) g_free(m->args_pos);
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-04-24 06:43:01 +00:00
|
|
|
m->args_pos = (int*)(void *)args_pos->data;
|
2007-01-29 04:57:23 +00:00
|
|
|
|
|
|
|
g_ptr_array_free(parts,FALSE);
|
|
|
|
g_array_free(args_pos,FALSE);
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
m->argc = argc;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
m->usable = TRUE;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-29 14:11:44 +00:00
|
|
|
macro_dump(m,NULL);
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void macro_free(void* r) {
|
|
|
|
dfilter_macro_t* m = r;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
g_free(m->name);
|
|
|
|
g_free(m->text);
|
|
|
|
g_free(m->priv);
|
|
|
|
g_free(m->parts);
|
|
|
|
g_free(m->args_pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void* macro_copy(void* dest, const void* orig, unsigned len _U_) {
|
|
|
|
dfilter_macro_t* d = dest;
|
|
|
|
const dfilter_macro_t* m = orig;
|
|
|
|
guint nparts = 0;
|
|
|
|
|
|
|
|
d->name = g_strdup(m->name);
|
|
|
|
d->text = g_strdup(m->text);
|
|
|
|
d->usable = m->usable;
|
|
|
|
|
|
|
|
if (m->parts) {
|
2007-05-03 16:11:18 +00:00
|
|
|
do nparts++; while (m->parts[nparts]);
|
2007-01-29 04:57:23 +00:00
|
|
|
d->priv = g_strdup(m->priv);
|
|
|
|
d->parts = g_memdup(m->parts,nparts*sizeof(void*));
|
|
|
|
d->args_pos = g_memdup(m->args_pos,(--nparts)*sizeof(int));
|
|
|
|
}
|
2007-05-03 16:11:18 +00:00
|
|
|
|
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
|
2007-04-23 10:59:26 +00:00
|
|
|
static gboolean macro_name_chk(void* r _U_, const char* in_name, unsigned name_len, void* u1 _U_, void* u2 _U_, const char** error) {
|
2007-01-29 04:57:23 +00:00
|
|
|
guint i;
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-01-29 04:57:23 +00:00
|
|
|
for (i=0; i < name_len; i++) {
|
2007-04-13 23:32:21 +00:00
|
|
|
if (!(in_name[i] == '_' || isalnum((int)in_name[i]) ) ) {
|
2007-01-29 04:57:23 +00:00
|
|
|
*error = "invalid char in name";
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
return i > 0 ? TRUE : FALSE;
|
2007-01-29 04:57:23 +00:00
|
|
|
}
|
|
|
|
|
2007-02-03 14:25:02 +00:00
|
|
|
UAT_CSTRING_CB_DEF(macro,name,dfilter_macro_t)
|
|
|
|
UAT_CSTRING_CB_DEF(macro,text,dfilter_macro_t)
|
2007-01-29 04:57:23 +00:00
|
|
|
|
|
|
|
void dfilter_macro_init(void) {
|
2007-02-03 14:25:02 +00:00
|
|
|
static uat_field_t uat_fields[] = {
|
2007-02-12 19:57:41 +00:00
|
|
|
UAT_FLD_CSTRING_OTHER(macro,name,macro_name_chk,"The name of the macro."),
|
|
|
|
UAT_FLD_CSTRING_ISPRINT(macro,text,"The text this macro resolves to."),
|
2007-02-03 14:25:02 +00:00
|
|
|
UAT_END_FIELDS
|
|
|
|
};
|
2007-05-03 16:11:18 +00:00
|
|
|
|
2007-02-12 19:57:41 +00:00
|
|
|
dfilter_macro_uat = uat_new("Display Filter Macros",
|
2007-04-03 21:17:13 +00:00
|
|
|
sizeof(dfilter_macro_t),
|
|
|
|
DFILTER_MACRO_FILENAME,
|
|
|
|
(void*) ¯os,
|
|
|
|
&num_macros,
|
|
|
|
NULL,
|
|
|
|
"ChDisplayFilterMacrosSection",
|
|
|
|
macro_copy,
|
|
|
|
macro_update,
|
|
|
|
macro_free,
|
|
|
|
uat_fields);
|
2007-01-29 04:57:23 +00:00
|
|
|
}
|
2007-01-29 10:23:38 +00:00
|
|
|
|
|
|
|
void dfilter_macro_get_uat(void** p) {
|
|
|
|
*p = dfilter_macro_uat;
|
|
|
|
}
|