aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuis Ontanon <luis.ontanon@gmail.com>2006-10-03 12:07:10 +0000
committerLuis Ontanon <luis.ontanon@gmail.com>2006-10-03 12:07:10 +0000
commit161b9a55eaecb0acac3751bb944bb93551406c4a (patch)
treea6c0d2ffbc11271dd3103fb35164112ba3cda3f6
parent179039652b0c64691f9f13d2ae3451fca3252700 (diff)
more Lua APIs:
- set_filter() : sets the main window filter - reload() : reloads the current capture file - copy_to_clipboard() : copies its first arfg to the clipboard - open_capture_file() : opens a capture file for viewing (still broken) svn path=/trunk/; revision=19404
-rw-r--r--epan/funnel.h4
-rw-r--r--epan/wslua/wslua_gui.c69
-rw-r--r--gtk/funnel_stat.c59
-rw-r--r--tap-funnel.c3
4 files changed, 134 insertions, 1 deletions
diff --git a/epan/funnel.h b/epan/funnel.h
index 3cd7eb22ea..65264a896a 100644
--- a/epan/funnel.h
+++ b/epan/funnel.h
@@ -83,6 +83,10 @@ typedef struct _funnel_ops_t {
gpointer user_data);
void (*retap_packets)(void);
+ void (*copy_to_clipboard)(GString *str);
+ void (*set_filter)(const char*);
+ gboolean (*open_file)(const char* fname, const char* filter, char** error);
+ void (*reload)(void);
} funnel_ops_t;
diff --git a/epan/wslua/wslua_gui.c b/epan/wslua/wslua_gui.c
index bd174041b8..0db396b313 100644
--- a/epan/wslua/wslua_gui.c
+++ b/epan/wslua/wslua_gui.c
@@ -503,3 +503,72 @@ WSLUA_FUNCTION wslua_retap_packets(lua_State* L) {
}
+WSLUA_FUNCTION wslua_copy_to_clipboard(lua_State* L) { /* copy a string into the clipboard */
+#define WSLUA_ARG_copy_to_clipboard_TEXT 1 /* The string to be copied into the clipboard. */
+ const char* copied_str = luaL_checkstring(L,WSLUA_ARG_copy_to_clipboard_TEXT);
+ GString* gstr;
+ if (!ops->copy_to_clipboard) {
+ WSLUA_ERROR(wslua_copy_to_clipboard, "does not work on TShark");
+ }
+
+ if (!copied_str) {
+ WSLUA_ARG_ERROR(copy_to_clipboard,TEXT,"must be a string");
+ }
+
+ gstr = g_string_new(copied_str);
+
+ ops->copy_to_clipboard(gstr);
+
+ g_string_free(gstr,TRUE);
+
+ return 0;
+}
+
+WSLUA_FUNCTION wslua_open_capture_file(lua_State* L) {
+#define WSLUA_ARG_open_capture_file_FILENAME 1 /* The name of the file to be opened. */
+#define WSLUA_ARG_open_capture_file_FILTER 2 /* A filter tgo be applied as the file gets opened. */
+
+ const char* fname = luaL_checkstring(L,WSLUA_ARG_open_capture_file_FILENAME);
+ const char* filter = luaL_optstring(L,WSLUA_ARG_open_capture_file_FILTER,NULL);
+ char* error = NULL;
+
+ if (!ops->open_file) {
+ WSLUA_ERROR(wslua_open_capture_file, "does not work on TShark");
+ }
+
+ if (!fname) {
+ WSLUA_ARG_ERROR(open_capture_file,FILENAME,"must be a string");
+ }
+
+ if (! ops->open_file(fname,filter,&error) ) {
+ lua_pushboolean(L,FALSE);
+
+ if (error)
+ lua_pushstring(L,error);
+ else
+ lua_pushnil(L);
+
+ return 2;
+ } else {
+ lua_pushboolean(L,TRUE);
+ return 1;
+ }
+}
+
+WSLUA_FUNCTION wslua_set_filter(lua_State* L) { /* set the main filter text */
+#define WSLUA_ARG_set_filter_TEXT 1 /* The filter's text. */
+ const char* filter_str = luaL_checkstring(L,WSLUA_ARG_set_filter_TEXT);
+
+ if (!ops->set_filter) {
+ WSLUA_ERROR(wslua_set_filter, "does not work on TShark");
+ }
+
+ if (!filter_str) {
+ WSLUA_ARG_ERROR(set_filter,TEXT,"must be a string");
+ }
+
+ ops->set_filter(filter_str);
+
+ return 0;
+}
+
diff --git a/gtk/funnel_stat.c b/gtk/funnel_stat.c
index 506a549cd9..be4d2347b7 100644
--- a/gtk/funnel_stat.c
+++ b/gtk/funnel_stat.c
@@ -59,6 +59,7 @@
#include <epan/prefs.h>
#include "column_prefs.h"
#include "prefs_dlg.h"
+#include "file.h"
#include "gtkglobals.h"
@@ -499,6 +500,9 @@ static void funnel_new_dialog(const gchar* title,
gtk_widget_show(win);
}
+static void funnel_set_filter(const char* filter_string) {
+ gtk_entry_set_text(GTK_ENTRY(main_display_filter_widget), filter_string);
+}
/* XXX: finish this */
static void funnel_logger(const gchar *log_domain _U_,
@@ -512,6 +516,55 @@ static void funnel_retap_packets(void) {
cf_retap_packets(&cfile, FALSE);
}
+static gboolean funnel_open_file(const char* fname, const char* filter, char** error) {
+ int err = 0;
+ dfilter_t *rfcode = NULL;
+
+ *error = "no error";
+
+ switch (cfile.state) {
+ case FILE_CLOSED:
+ break;
+ case FILE_READ_DONE:
+ case FILE_READ_ABORTED:
+ cf_close(&cfile);
+ break;
+ case FILE_READ_IN_PROGRESS:
+ *error = "file read in progress";
+ return FALSE;
+ }
+
+ if (filter) {
+ if (!dfilter_compile(filter, &rfcode)) {
+ *error = dfilter_error_msg ? dfilter_error_msg : "cannot compile filter";
+ return FALSE;
+ }
+ }
+
+
+ if (cf_open(&cfile, fname, FALSE, &err) != CF_OK) {
+ *error = strerror(err);
+ if (rfcode != NULL) dfilter_free(rfcode);
+ return FALSE;
+ }
+
+ cfile.rfcode = rfcode;
+
+ switch (cf_read(&cfile)) {
+ case CF_READ_OK:
+ case CF_READ_ERROR:
+ break;
+ default:
+ *error = "problem while reading file";
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void funnel_reload() {
+ if (cfile.state == FILE_READ_DONE) cf_reload(&cfile);
+}
static const funnel_ops_t funnel_ops = {
new_text_window,
@@ -527,7 +580,11 @@ static const funnel_ops_t funnel_ops = {
/*...,*/
funnel_new_dialog,
funnel_logger,
- funnel_retap_packets
+ funnel_retap_packets,
+ copy_to_clipboard,
+ funnel_set_filter,
+ funnel_open_file,
+ funnel_reload
};
diff --git a/tap-funnel.c b/tap-funnel.c
index 10711afc0c..95784f96bc 100644
--- a/tap-funnel.c
+++ b/tap-funnel.c
@@ -98,6 +98,9 @@ static const funnel_ops_t funnel_ops = {
/*...,*/
NULL,
funnel_logger,
+ NULL,
+ NULL,
+ NULL,
NULL
};