4 * (c) 2006, Luis E. Garcia Ontanon <luis@ontanon.org>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
29 #include <epan/emem.h>
33 /* WSLUA_MODULE Gui GUI support */
35 static const funnel_ops_t
* ops
= NULL
;
37 struct _lua_menu_data
{
42 static int menu_cb_error_handler(lua_State
* L
) {
43 const gchar
* error
= lua_tostring(L
,1);
44 report_failure("Lua: Error During execution of Menu Callback:\n %s",error
);
48 WSLUA_FUNCTION
wslua_gui_enabled(lua_State
* L
) { /* Checks whether the GUI facility is enabled. */
49 lua_pushboolean(L
,GPOINTER_TO_INT(ops
&& ops
->add_button
));
50 WSLUA_RETURN(1); /* A boolean: true if it is enabled, false if it isn't. */
53 static void lua_menu_callback(gpointer data
) {
54 struct _lua_menu_data
* md
= (struct _lua_menu_data
*)data
;
58 lua_pushcfunction(L
,menu_cb_error_handler
);
59 lua_rawgeti(L
, LUA_REGISTRYINDEX
, md
->cb_ref
);
61 switch ( lua_pcall(L
,0,0,1) ) {
65 g_warning("Runtime error while calling menu callback");
68 g_warning("Memory alloc error while calling menu callback");
71 g_assert_not_reached();
78 WSLUA_FUNCTION
wslua_register_menu(lua_State
* L
) { /* Register a menu item in one of the main menus. */
79 #define WSLUA_ARG_register_menu_NAME 1 /* The name of the menu item. The submenus are to be separated by '/'s. (string) */
80 #define WSLUA_ARG_register_menu_ACTION 2 /* The function to be called when the menu item is invoked. (function taking no arguments and returning nothing) */
81 #define WSLUA_OPTARG_register_menu_GROUP 3 /* The menu group into which the menu item is to be inserted. If omitted, defaults to MENU_STAT_GENERIC. One of:
82 MENU_STAT_UNSORTED (Statistics),
83 MENU_STAT_GENERIC (Statistics, first section),
84 MENU_STAT_CONVERSATION (Statistics/Conversation List),
85 MENU_STAT_ENDPOINT (Statistics/Endpoint List),
86 MENU_STAT_RESPONSE (Statistics/Service Response Time),
87 MENU_STAT_TELEPHONY (Telephony), MENU_ANALYZE (Analyze),
88 MENU_ANALYZE_CONVERSATION (Analyze/Conversation Filter),
89 MENU_TOOLS_UNSORTED (Tools). (number) */
91 const gchar
* name
= luaL_checkstring(L
,WSLUA_ARG_register_menu_NAME
);
92 struct _lua_menu_data
* md
;
93 gboolean retap
= FALSE
;
94 register_stat_group_t group
= (register_stat_group_t
)luaL_optnumber(L
,WSLUA_OPTARG_register_menu_GROUP
,REGISTER_STAT_GROUP_GENERIC
);
96 if ( group
> REGISTER_TOOLS_GROUP_UNSORTED
)
97 WSLUA_OPTARG_ERROR(register_menu
,GROUP
,"Must be a defined MENU_* (see init.lua)");
100 WSLUA_ARG_ERROR(register_menu
,NAME
,"Must be a string");
102 if (!lua_isfunction(L
,WSLUA_ARG_register_menu_ACTION
))
103 WSLUA_ARG_ERROR(register_menu
,ACTION
,"Must be a function");
105 md
= (struct _lua_menu_data
*)g_malloc(sizeof(struct _lua_menu_data
));
109 md
->cb_ref
= luaL_ref(L
, LUA_REGISTRYINDEX
);
112 funnel_register_menu(name
,
124 struct _dlg_cb_data
{
129 static int dlg_cb_error_handler(lua_State
* L
) {
130 const gchar
* error
= lua_tostring(L
,1);
131 report_failure("Lua: Error During execution of dialog callback:\n %s",error
);
135 static void lua_dialog_cb(gchar
** user_input
, void* data
) {
136 struct _dlg_cb_data
* dcbd
= (struct _dlg_cb_data
*)data
;
139 lua_State
* L
= dcbd
->L
;
142 lua_pushcfunction(L
,dlg_cb_error_handler
);
143 lua_rawgeti(L
, LUA_REGISTRYINDEX
, dcbd
->func_ref
);
145 for (i
= 0; (input
= user_input
[i
]) ; i
++) {
146 lua_pushstring(L
,input
);
152 switch ( lua_pcall(L
,i
,0,1) ) {
156 g_warning("Runtime error while calling dialog callback");
159 g_warning("Memory alloc error while calling dialog callback");
162 g_assert_not_reached();
168 struct _close_cb_data
{
175 static int text_win_close_cb_error_handler(lua_State
* L
) {
176 const gchar
* error
= lua_tostring(L
,1);
177 report_failure("Lua: Error During execution of TextWindow close callback:\n %s",error
);
181 static void text_win_close_cb(void* data
) {
182 struct _close_cb_data
* cbd
= (struct _close_cb_data
*)data
;
183 lua_State
* L
= cbd
->L
;
185 if (cbd
->L
) { /* close function is set */
188 lua_pushcfunction(L
,text_win_close_cb_error_handler
);
189 lua_rawgeti(L
, LUA_REGISTRYINDEX
, cbd
->func_ref
);
191 switch ( lua_pcall(L
,0,0,1) ) {
195 g_warning("Runtime error during execution of TextWindow close callback");
198 g_warning("Memory alloc error during execution of TextWindow close callback");
205 if (cbd
->wslua_tw
->expired
) {
206 g_free(cbd
->wslua_tw
);
208 cbd
->wslua_tw
->expired
= TRUE
;
213 WSLUA_FUNCTION
wslua_new_dialog(lua_State
* L
) { /* Pops up a new dialog */
214 #define WSLUA_ARG_new_dialog_TITLE 1 /* Title of the dialog's window. */
215 #define WSLUA_ARG_new_dialog_ACTION 2 /* Action to be performed when OKd. */
216 /* WSLUA_MOREARGS new_dialog A series of strings to be used as labels of the dialog's fields */
219 int top
= lua_gettop(L
);
222 struct _dlg_cb_data
* dcbd
;
225 luaL_error(L
,"the GUI facility has to be enabled");
229 if (!ops
->new_dialog
) {
230 WSLUA_ERROR(new_dialog
,"GUI not available");
233 if (! (title
= luaL_checkstring(L
,WSLUA_ARG_new_dialog_TITLE
)) ) {
234 WSLUA_ARG_ERROR(new_dialog
,TITLE
,"Must be a string");
237 if (! lua_isfunction(L
,WSLUA_ARG_new_dialog_ACTION
)) {
238 WSLUA_ARG_ERROR(new_dialog
,ACTION
,"Must be a function");
242 WSLUA_ERROR(new_dialog
,"At least one field required");
246 dcbd
= (struct _dlg_cb_data
*)g_malloc(sizeof(struct _dlg_cb_data
));
252 dcbd
->func_ref
= luaL_ref(L
, LUA_REGISTRYINDEX
);
255 labels
= g_ptr_array_new();
259 for (i
= 1; i
<= top
; i
++) {
260 gchar
* label
= (gchar
*)luaL_checkstring(L
,i
);
262 /* XXX leaks labels on error */
264 WSLUA_ERROR(new_dialog
,"All fields must be strings");
266 g_ptr_array_add(labels
,label
);
269 g_ptr_array_add(labels
,NULL
);
271 ops
->new_dialog(title
, (const gchar
**)labels
->pdata
, lua_dialog_cb
, dcbd
);
273 g_ptr_array_free(labels
,FALSE
);
280 WSLUA_CLASS_DEFINE(ProgDlg
,NOP
,NOP
); /* Manages a progress bar dialog. */
282 WSLUA_CONSTRUCTOR
ProgDlg_new(lua_State
* L
) { /* Creates a new TextWindow. */
283 #define WSLUA_OPTARG_ProgDlg_new_TITLE 2 /* Title of the new window, defaults to "Progress". */
284 #define WSLUA_OPTARG_ProgDlg_new_TASK 3 /* Current task, defaults to "". */
285 ProgDlg pd
= (ProgDlg
)g_malloc(sizeof(struct _wslua_progdlg
));
286 pd
->title
= g_strdup(luaL_optstring(L
,WSLUA_OPTARG_ProgDlg_new_TITLE
,"Progress"));
287 pd
->task
= g_strdup(luaL_optstring(L
,WSLUA_OPTARG_ProgDlg_new_TASK
,""));
290 if (ops
->new_progress_window
) {
291 pd
->pw
= ops
->new_progress_window(pd
->title
,pd
->task
,TRUE
,&(pd
->stopped
));
293 WSLUA_ERROR(ProgDlg_new
, "GUI not available");
298 WSLUA_RETURN(1); /* The newly created TextWindow object. */
301 WSLUA_METHOD
ProgDlg_update(lua_State
* L
) { /* Appends text */
302 #define WSLUA_ARG_ProgDlg_update_PROGRESS 2 /* Part done ( e.g. 0.75 ). */
303 #define WSLUA_OPTARG_ProgDlg_update_TASK 3 /* Current task, defaults to "". */
304 ProgDlg pd
= checkProgDlg(L
,1);
305 double pr
= lua_tonumber(L
,WSLUA_ARG_ProgDlg_update_PROGRESS
);
306 const gchar
* task
= luaL_optstring(L
,WSLUA_OPTARG_ProgDlg_update_TASK
,"");
308 if (!ops
->update_progress
) {
309 WSLUA_ERROR(ProgDlg_update
,"GUI not available");
313 pd
->task
= g_strdup(task
);
315 /* XXX, dead code: pd already dereferenced. should it be: !pd->task?
317 WSLUA_ERROR(ProgDlg_update,"Cannot be called for something not a ProgDlg");
320 if (pr
>= 0.0 && pr
<= 1.0) {
321 ops
->update_progress(pd
->pw
, (float) pr
, task
);
323 WSLUA_ERROR(ProgDlg_update
,"Progress value out of range (must be between 0.0 and 1.0)");
329 WSLUA_METHOD
ProgDlg_stopped(lua_State
* L
) { /* Checks wheher the user has pressed the stop button. */
330 ProgDlg pd
= checkProgDlg(L
,1);
333 WSLUA_ERROR(ProgDlg_stopped
,"Cannot be called for something not a ProgDlg");
336 lua_pushboolean(L
,pd
->stopped
);
338 WSLUA_RETURN(1); /* true if the user has asked to stop the progress. */
343 WSLUA_METHOD
ProgDlg_close(lua_State
* L
) { /* Appends text */
344 ProgDlg pd
= checkProgDlg(L
,1);
346 if (!ops
->destroy_progress_window
) {
347 WSLUA_ERROR(ProgDlg_close
,"GUI not available");
351 WSLUA_ERROR(ProgDlg_update
,"Cannot be called for something not a ProgDlg");
355 ops
->destroy_progress_window(pd
->pw
);
362 static int ProgDlg__tostring(lua_State
* L
) {
363 ProgDlg pd
= checkProgDlg(L
,1);
366 lua_pushstring(L
,ep_strdup_printf("%sstopped",pd
->stopped
?"":"not "));
368 luaL_error(L
, "ProgDlg__tostring has being passed something else!");
374 /* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */
375 static int ProgDlg__gc(lua_State
* L
) {
376 ProgDlg pd
= checkProgDlg(L
,1);
379 if (pd
->pw
&& ops
->destroy_progress_window
) {
380 ops
->destroy_progress_window(pd
->pw
);
385 luaL_error(L
, "ProgDlg__gc has being passed something else!");
392 WSLUA_METHODS ProgDlg_methods
[] = {
393 WSLUA_CLASS_FNREG(ProgDlg
,new),
394 WSLUA_CLASS_FNREG(ProgDlg
,update
),
395 WSLUA_CLASS_FNREG(ProgDlg
,stopped
),
396 WSLUA_CLASS_FNREG(ProgDlg
,close
),
400 WSLUA_META ProgDlg_meta
[] = {
401 {"__tostring", ProgDlg__tostring
},
405 int ProgDlg_register(lua_State
* L
) {
407 ops
= funnel_get_funnel_ops();
409 WSLUA_REGISTER_CLASS(ProgDlg
);
416 WSLUA_CLASS_DEFINE(TextWindow
,NOP
,NOP
); /* Manages a text window. */
418 /* XXX: button and close callback data is being leaked */
419 /* XXX: lua callback function and TextWindow are not garbage collected because
420 they stay in LUA_REGISTRYINDEX forever */
422 WSLUA_CONSTRUCTOR
TextWindow_new(lua_State
* L
) { /* Creates a new TextWindow. */
423 #define WSLUA_OPTARG_TextWindow_new_TITLE 1 /* Title of the new window. */
426 TextWindow tw
= NULL
;
427 struct _close_cb_data
* default_cbd
;
429 if (!ops
->new_text_window
|| !ops
->set_close_cb
) {
430 WSLUA_ERROR(TextWindow_new
,"GUI not available");
433 title
= luaL_optstring(L
,WSLUA_OPTARG_TextWindow_new_TITLE
,"Untitled Window");
434 tw
= (struct _wslua_tw
*)g_malloc(sizeof(struct _wslua_tw
));
436 tw
->ws_tw
= ops
->new_text_window(title
);
438 default_cbd
= (struct _close_cb_data
*)g_malloc(sizeof(struct _close_cb_data
));
440 default_cbd
->L
= NULL
;
441 default_cbd
->func_ref
= 0;
442 default_cbd
->wslua_tw
= tw
;
444 ops
->set_close_cb(tw
->ws_tw
,text_win_close_cb
,default_cbd
);
446 pushTextWindow(L
,tw
);
448 WSLUA_RETURN(1); /* The newly created TextWindow object. */
451 WSLUA_METHOD
TextWindow_set_atclose(lua_State
* L
) { /* Set the function that will be called when the window closes */
452 #define WSLUA_ARG_TextWindow_at_close_ACTION 2 /* A function to be executed when the user closes the window */
454 TextWindow tw
= checkTextWindow(L
,1);
455 struct _close_cb_data
* cbd
;
457 if (!ops
->set_close_cb
) {
458 WSLUA_ERROR(TextWindow_set_atclose
,"GUI not available");
462 WSLUA_ERROR(TextWindow_at_close
,"Cannot be called for something not a TextWindow");
466 if (! lua_isfunction(L
,2))
467 WSLUA_ARG_ERROR(TextWindow_at_close
,ACTION
,"Must be a function");
469 cbd
= (struct _close_cb_data
*)g_malloc(sizeof(struct _close_cb_data
));
472 cbd
->func_ref
= luaL_ref(L
, LUA_REGISTRYINDEX
);
475 ops
->set_close_cb(tw
->ws_tw
,text_win_close_cb
,cbd
);
477 WSLUA_RETURN(1); /* The TextWindow object. */
480 WSLUA_METHOD
TextWindow_set(lua_State
* L
) { /* Sets the text. */
481 #define WSLUA_ARG_TextWindow_set_TEXT 2 /* The text to be used. */
483 TextWindow tw
= checkTextWindow(L
,1);
484 const gchar
* text
= luaL_checkstring(L
,WSLUA_ARG_TextWindow_set_TEXT
);
487 WSLUA_ERROR(TextWindow_set
,"GUI not available");
490 WSLUA_ERROR(TextWindow_set
,"Cannot be called for something not a TextWindow");
493 WSLUA_ERROR(TextWindow_set
,"Expired TextWindow");
496 WSLUA_ARG_ERROR(TextWindow_set
,TEXT
,"Must be a string");
498 ops
->set_text(tw
->ws_tw
,text
);
500 WSLUA_RETURN(1); /* The TextWindow object. */
503 WSLUA_METHOD
TextWindow_append(lua_State
* L
) { /* Appends text */
504 #define WSLUA_ARG_TextWindow_append_TEXT 2 /* The text to be appended */
505 TextWindow tw
= checkTextWindow(L
,1);
506 const gchar
* text
= luaL_checkstring(L
,WSLUA_ARG_TextWindow_append_TEXT
);
508 if (!ops
->append_text
)
509 WSLUA_ERROR(TextWindow_append
,"GUI not available");
512 WSLUA_ERROR(TextWindow_append
,"Cannot be called for something not a TextWindow");
515 WSLUA_ERROR(TextWindow_append
,"Expired TextWindow");
518 WSLUA_ARG_ERROR(TextWindow_append
,TEXT
,"Must be a string");
520 ops
->append_text(tw
->ws_tw
,text
);
522 WSLUA_RETURN(1); /* The TextWindow object. */
525 WSLUA_METHOD
TextWindow_prepend(lua_State
* L
) { /* Prepends text */
526 #define WSLUA_ARG_TextWindow_prepend_TEXT 2 /* The text to be appended */
527 TextWindow tw
= checkTextWindow(L
,1);
528 const gchar
* text
= luaL_checkstring(L
,WSLUA_ARG_TextWindow_prepend_TEXT
);
530 if (!ops
->prepend_text
)
531 WSLUA_ERROR(TextWindow_prepend
,"GUI not available");
534 WSLUA_ERROR(TextWindow_prepend
,"Cannot be called for something not a TextWindow");
537 WSLUA_ERROR(TextWindow_prepend
,"Expired TextWindow");
540 WSLUA_ARG_ERROR(TextWindow_prepend
,TEXT
,"Must be a string");
542 ops
->prepend_text(tw
->ws_tw
,text
);
544 WSLUA_RETURN(1); /* The TextWindow object. */
547 WSLUA_METHOD
TextWindow_clear(lua_State
* L
) { /* Erases all text in the window. */
548 TextWindow tw
= checkTextWindow(L
,1);
550 if (!ops
->clear_text
)
551 WSLUA_ERROR(TextWindow_clear
,"GUI not available");
554 WSLUA_ERROR(TextWindow_clear
,"Cannot be called for something not a TextWindow");
557 WSLUA_ERROR(TextWindow_clear
,"Expired TextWindow");
559 ops
->clear_text(tw
->ws_tw
);
561 WSLUA_RETURN(1); /* The TextWindow object. */
564 WSLUA_METHOD
TextWindow_get_text(lua_State
* L
) { /* Get the text of the window */
565 TextWindow tw
= checkTextWindow(L
,1);
569 WSLUA_ERROR(TextWindow_get_text
,"GUI not available");
572 WSLUA_ERROR(TextWindow_get_text
,"Cannot be called for something not a TextWindow");
575 WSLUA_ERROR(TextWindow_get_text
,"Expired TextWindow");
577 text
= ops
->get_text(tw
->ws_tw
);
579 lua_pushstring(L
,text
);
580 WSLUA_RETURN(1); /* The TextWindow's text. */
583 /* Gets registered as metamethod automatically by WSLUA_REGISTER_CLASS/META */
584 static int TextWindow__gc(lua_State
* L
) {
585 TextWindow tw
= checkTextWindow(L
,1);
592 if (ops
->destroy_text_window
) {
593 ops
->destroy_text_window(tw
->ws_tw
);
603 WSLUA_METHOD
TextWindow_set_editable(lua_State
* L
) { /* Make this window editable */
604 #define WSLUA_OPTARG_TextWindow_set_editable_EDITABLE 2 /* A boolean flag, defaults to true */
606 TextWindow tw
= checkTextWindow(L
,1);
607 gboolean editable
= wslua_optbool(L
,WSLUA_OPTARG_TextWindow_set_editable_EDITABLE
,TRUE
);
609 if (!ops
->set_editable
)
610 WSLUA_ERROR(TextWindow_set_editable
,"GUI not available");
613 WSLUA_ERROR(TextWindow_set_editable
,"Cannot be called for something not a TextWindow");
616 WSLUA_ERROR(TextWindow_set_editable
,"Expired TextWindow");
618 if (ops
->set_editable
)
619 ops
->set_editable(tw
->ws_tw
,editable
);
621 WSLUA_RETURN(1); /* The TextWindow object. */
624 typedef struct _wslua_bt_cb_t
{
630 static gboolean
wslua_button_callback(funnel_text_window_t
* ws_tw
, void* data
) {
631 wslua_bt_cb_t
* cbd
= (wslua_bt_cb_t
*)data
;
632 lua_State
* L
= cbd
->L
;
633 (void) ws_tw
; /* ws_tw is unused since we need wslua_tw_ref and it is stored in cbd */
636 lua_pushcfunction(L
,dlg_cb_error_handler
);
637 lua_rawgeti(L
, LUA_REGISTRYINDEX
, cbd
->func_ref
);
638 lua_rawgeti(L
, LUA_REGISTRYINDEX
, cbd
->wslua_tw_ref
);
640 switch ( lua_pcall(L
,1,0,1) ) {
644 g_warning("Runtime error while calling button callback");
647 g_warning("Memory alloc error while calling button callback");
650 g_assert_not_reached();
657 WSLUA_METHOD
TextWindow_add_button(lua_State
* L
) {
658 #define WSLUA_ARG_TextWindow_add_button_LABEL 2 /* The label of the button */
659 #define WSLUA_ARG_TextWindow_add_button_FUNCTION 3 /* The function to be called when clicked */
660 TextWindow tw
= checkTextWindow(L
,1);
661 const gchar
* label
= luaL_checkstring(L
,WSLUA_ARG_TextWindow_add_button_LABEL
);
666 if (!ops
->add_button
)
667 WSLUA_ERROR(TextWindow_add_button
,"GUI not available");
670 WSLUA_ERROR(TextWindow_add_button
,"Cannot be called for something not a TextWindow");
673 WSLUA_ERROR(TextWindow_add_button
,"Expired TextWindow");
675 if (! lua_isfunction(L
,WSLUA_ARG_TextWindow_add_button_FUNCTION
) )
676 WSLUA_ARG_ERROR(TextWindow_add_button
,FUNCTION
,"must be a function");
680 if (ops
->add_button
) {
681 fbt
= (funnel_bt_t
*)g_malloc(sizeof(funnel_bt_t
));
682 cbd
= (wslua_bt_cb_t
*)g_malloc(sizeof(wslua_bt_cb_t
));
685 fbt
->func
= wslua_button_callback
;
687 fbt
->free_fcn
= g_free
;
688 fbt
->free_data_fcn
= g_free
;
691 cbd
->func_ref
= luaL_ref(L
, LUA_REGISTRYINDEX
);
692 cbd
->wslua_tw_ref
= luaL_ref(L
, LUA_REGISTRYINDEX
);
694 ops
->add_button(tw
->ws_tw
,fbt
,label
);
697 WSLUA_RETURN(1); /* The TextWindow object. */
700 WSLUA_METHODS TextWindow_methods
[] = {
701 WSLUA_CLASS_FNREG(TextWindow
,new),
702 WSLUA_CLASS_FNREG(TextWindow
,set
),
703 WSLUA_CLASS_FNREG(TextWindow
,new),
704 WSLUA_CLASS_FNREG(TextWindow
,append
),
705 WSLUA_CLASS_FNREG(TextWindow
,prepend
),
706 WSLUA_CLASS_FNREG(TextWindow
,clear
),
707 WSLUA_CLASS_FNREG(TextWindow
,set_atclose
),
708 WSLUA_CLASS_FNREG(TextWindow
,set_editable
),
709 WSLUA_CLASS_FNREG(TextWindow
,get_text
),
710 WSLUA_CLASS_FNREG(TextWindow
,add_button
),
714 WSLUA_META TextWindow_meta
[] = {
715 {"__tostring", TextWindow_get_text
},
719 int TextWindow_register(lua_State
* L
) {
721 ops
= funnel_get_funnel_ops();
723 WSLUA_REGISTER_CLASS(TextWindow
);
729 WSLUA_FUNCTION
wslua_retap_packets(lua_State
* L
) {
731 Rescan all packets and just run taps - don't reconstruct the display.
733 if ( ops
->retap_packets
) {
734 ops
->retap_packets();
736 WSLUA_ERROR(wslua_retap_packets
, "GUI not available");
743 WSLUA_FUNCTION
wslua_copy_to_clipboard(lua_State
* L
) { /* Copy a string into the clipboard */
744 #define WSLUA_ARG_copy_to_clipboard_TEXT 1 /* The string to be copied into the clipboard. */
745 const char* copied_str
= luaL_checkstring(L
,WSLUA_ARG_copy_to_clipboard_TEXT
);
747 if (!ops
->copy_to_clipboard
) {
748 WSLUA_ERROR(copy_to_clipboard
, "GUI not available");
752 WSLUA_ARG_ERROR(copy_to_clipboard
,TEXT
,"Must be a string");
755 gstr
= g_string_new(copied_str
);
757 ops
->copy_to_clipboard(gstr
);
759 g_string_free(gstr
,TRUE
);
764 WSLUA_FUNCTION
wslua_open_capture_file(lua_State
* L
) { /* Open and display a capture file */
765 #define WSLUA_ARG_open_capture_file_FILENAME 1 /* The name of the file to be opened. */
766 #define WSLUA_ARG_open_capture_file_FILTER 2 /* A filter to be applied as the file gets opened. */
768 const char* fname
= luaL_checkstring(L
,WSLUA_ARG_open_capture_file_FILENAME
);
769 const char* filter
= luaL_optstring(L
,WSLUA_ARG_open_capture_file_FILTER
,NULL
);
770 const char* error
= NULL
;
772 if (!ops
->open_file
) {
773 WSLUA_ERROR(open_capture_file
, "GUI not available");
777 WSLUA_ARG_ERROR(open_capture_file
,FILENAME
,"Must be a string");
780 if (! ops
->open_file(fname
,filter
,&error
) ) {
781 lua_pushboolean(L
,FALSE
);
784 lua_pushstring(L
,error
);
790 lua_pushboolean(L
,TRUE
);
795 WSLUA_FUNCTION
wslua_get_filter(lua_State
* L
) { /* Get the main filter text */
796 const char *filter_str
= NULL
;
798 if (!ops
->get_filter
) {
799 WSLUA_ERROR(get_filter
, "GUI not available");
802 filter_str
= ops
->get_filter();
803 lua_pushstring(L
,filter_str
);
808 WSLUA_FUNCTION
wslua_set_filter(lua_State
* L
) { /* Set the main filter text */
809 #define WSLUA_ARG_set_filter_TEXT 1 /* The filter's text. */
810 const char* filter_str
= luaL_checkstring(L
,WSLUA_ARG_set_filter_TEXT
);
812 if (!ops
->set_filter
) {
813 WSLUA_ERROR(set_filter
, "GUI not available");
817 WSLUA_ARG_ERROR(set_filter
,TEXT
,"Must be a string");
820 ops
->set_filter(filter_str
);
825 WSLUA_FUNCTION
wslua_set_color_filter_slot(lua_State
* L
) { /* Set packet-coloring rule for the current session */
826 #define WSLUA_ARG_set_color_filter_slot_ROW 1 /* The index of the desired color in the temporary coloring rules list */
827 #define WSLUA_ARG_set_color_filter_slot_TEXT 2 /* Display filter for selecting packets to be colorized */
828 guint8 row
= luaL_checkint(L
,WSLUA_ARG_set_color_filter_slot_ROW
);
829 const gchar
* filter_str
= luaL_checkstring(L
,WSLUA_ARG_set_color_filter_slot_TEXT
);
831 if (!ops
->set_color_filter_slot
) {
832 WSLUA_ERROR(set_color_filter_slot
, "GUI not available");
836 WSLUA_ARG_ERROR(set_color_filter_slot
,TEXT
,"Must be a string");
839 ops
->set_color_filter_slot(row
, filter_str
);
844 WSLUA_FUNCTION
wslua_apply_filter(lua_State
* L
) { /* Apply the filter in the main filter box */
845 if (!ops
->apply_filter
) {
846 WSLUA_ERROR(apply_filter
, "GUI not available");
855 WSLUA_FUNCTION
wslua_reload(lua_State
* L
) { /* Reload the current capture file */
858 WSLUA_ERROR(reload
, "GUI not available");
867 WSLUA_FUNCTION
wslua_browser_open_url(lua_State
* L
) { /* Open an url in a browser */
868 #define WSLUA_ARG_browser_open_url_URL 1 /* The url. */
869 const char* url
= luaL_checkstring(L
,WSLUA_ARG_browser_open_url_URL
);
871 if (!ops
->browser_open_url
) {
872 WSLUA_ERROR(browser_open_url
, "GUI not available");
876 WSLUA_ARG_ERROR(browser_open_url
,URL
,"Must be a string");
879 ops
->browser_open_url(url
);
884 WSLUA_FUNCTION
wslua_browser_open_data_file(lua_State
* L
) { /* Open an file in a browser */
885 #define WSLUA_ARG_browser_open_data_file_FILENAME 1 /* The url. */
886 const char* file
= luaL_checkstring(L
,WSLUA_ARG_browser_open_data_file_FILENAME
);
888 if (!ops
->browser_open_data_file
) {
889 WSLUA_ERROR(browser_open_data_file
, "GUI not available");
893 WSLUA_ARG_ERROR(browser_open_data_file
,FILENAME
,"Must be a string");
896 ops
->browser_open_data_file(file
);