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
This commit is contained in:
Luis Ontanon 2006-10-03 12:07:10 +00:00
parent 179039652b
commit 161b9a55ea
4 changed files with 134 additions and 1 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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
};

View File

@ -98,6 +98,9 @@ static const funnel_ops_t funnel_ops = {
/*...,*/
NULL,
funnel_logger,
NULL,
NULL,
NULL,
NULL
};