diff options
author | Stig Bjørlykke <stig@bjorlykke.org> | 2011-06-25 20:47:13 +0000 |
---|---|---|
committer | Stig Bjørlykke <stig@bjorlykke.org> | 2011-06-25 20:47:13 +0000 |
commit | 4ac2487d3828fafc38c1ee035626f37a4c9c2d42 (patch) | |
tree | 5256a79f83c9647f18fdefcabe31f0648fcc8aca /epan/wslua/wslua_gui.c | |
parent | a4dc6c0a7d353ed69f125f8e44becb2f3afd776b (diff) |
From Tony Trinh via bug 6018:
Add NULL checks and fix typos in Lua error print-outs
From me:
Use the error message "GUI not available" when using GUI functions in tshark.
svn path=/trunk/; revision=37788
Diffstat (limited to 'epan/wslua/wslua_gui.c')
-rw-r--r-- | epan/wslua/wslua_gui.c | 83 |
1 files changed, 65 insertions, 18 deletions
diff --git a/epan/wslua/wslua_gui.c b/epan/wslua/wslua_gui.c index ae1109d418..530dfba88c 100644 --- a/epan/wslua/wslua_gui.c +++ b/epan/wslua/wslua_gui.c @@ -218,6 +218,10 @@ WSLUA_FUNCTION wslua_new_dialog(lua_State* L) { /* Pops up a new dialog */ return 0; } + if (!ops->new_dialog) { + WSLUA_ERROR(new_dialog,"GUI not available"); + } + if (! (title = luaL_checkstring(L,WSLUA_ARG_new_dialog_TITLE)) ) { WSLUA_ARG_ERROR(new_dialog,TITLE,"Must be a string"); } @@ -277,6 +281,8 @@ WSLUA_CONSTRUCTOR ProgDlg_new(lua_State* L) { /* Creates a new TextWindow. */ if (ops->new_progress_window) { pd->pw = ops->new_progress_window(pd->title,pd->task,TRUE,&(pd->stopped)); + } else { + WSLUA_ERROR(ProgDlg_new, "GUI not available"); } pushProgDlg(L,pd); @@ -291,6 +297,10 @@ WSLUA_METHOD ProgDlg_update(lua_State* L) { /* Appends text */ double pr = lua_tonumber(L,WSLUA_ARG_ProgDlg_update_PROGRESS); const gchar* task = luaL_optstring(L,WSLUA_OPTARG_ProgDlg_update_TASK,""); + if (!ops->update_progress) { + WSLUA_ERROR(ProgDlg_update,"GUI not available"); + } + g_free(pd->task); pd->task = g_strdup(task); @@ -325,6 +335,10 @@ WSLUA_METHOD ProgDlg_stopped(lua_State* L) { /* Checks wheher the user has press WSLUA_METHOD ProgDlg_close(lua_State* L) { /* Appends text */ ProgDlg pd = checkProgDlg(L,1); + if (!ops->destroy_progress_window) { + WSLUA_ERROR(ProgDlg_close,"GUI not available"); + } + if (!pd) { WSLUA_ERROR(ProgDlg_update,"Cannot be called for something not a ProgDlg"); } @@ -353,8 +367,10 @@ static int ProgDlg__gc(lua_State* L) { ProgDlg pd = checkProgDlg(L,1); if (pd) { - if (pd->pw) ops->destroy_progress_window(pd->pw); - + if (pd->pw && ops->destroy_progress_window) { + ops->destroy_progress_window(pd->pw); + } + g_free(pd); } else { luaL_error(L, "ProgDlg__gc has being passed something else!"); @@ -402,6 +418,10 @@ WSLUA_CONSTRUCTOR TextWindow_new(lua_State* L) { /* Creates a new TextWindow. */ TextWindow tw = NULL; struct _close_cb_data* default_cbd; + if (!ops->new_text_window || !ops->set_close_cb) { + WSLUA_ERROR(TextWindow_new,"GUI not available"); + } + title = luaL_optstring(L,WSLUA_OPTARG_TextWindow_new_TITLE,"Untitled Window"); tw = g_malloc(sizeof(struct _wslua_tw)); tw->expired = FALSE; @@ -426,6 +446,10 @@ WSLUA_METHOD TextWindow_set_atclose(lua_State* L) { /* Set the function that wil TextWindow tw = checkTextWindow(L,1); struct _close_cb_data* cbd; + if (!ops->set_close_cb) { + WSLUA_ERROR(TextWindow_set_atclose,"GUI not available"); + } + if (!tw) WSLUA_ERROR(TextWindow_at_close,"Cannot be called for something not a TextWindow"); @@ -451,11 +475,14 @@ WSLUA_METHOD TextWindow_set(lua_State* L) { /* Sets the text. */ TextWindow tw = checkTextWindow(L,1); const gchar* text = luaL_checkstring(L,WSLUA_ARG_TextWindow_set_TEXT); + if (!ops->set_text) + WSLUA_ERROR(TextWindow_set,"GUI not available"); + if (!tw) WSLUA_ERROR(TextWindow_set,"Cannot be called for something not a TextWindow"); if (tw->expired) - WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); + WSLUA_ERROR(TextWindow_set,"Expired TextWindow"); if (!text) WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Must be a string"); @@ -470,11 +497,14 @@ WSLUA_METHOD TextWindow_append(lua_State* L) { /* Appends text */ TextWindow tw = checkTextWindow(L,1); const gchar* text = luaL_checkstring(L,WSLUA_ARG_TextWindow_append_TEXT); + if (!ops->append_text) + WSLUA_ERROR(TextWindow_append,"GUI not available"); + if (!tw) WSLUA_ERROR(TextWindow_append,"Cannot be called for something not a TextWindow"); if (tw->expired) - WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); + WSLUA_ERROR(TextWindow_append,"Expired TextWindow"); if (!text) WSLUA_ARG_ERROR(TextWindow_append,TEXT,"Must be a string"); @@ -489,11 +519,14 @@ WSLUA_METHOD TextWindow_prepend(lua_State* L) { /* Prepends text */ TextWindow tw = checkTextWindow(L,1); const gchar* text = luaL_checkstring(L,WSLUA_ARG_TextWindow_prepend_TEXT); + if (!ops->prepend_text) + WSLUA_ERROR(TextWindow_prepend,"GUI not available"); + if (!tw) WSLUA_ERROR(TextWindow_prepend,"Cannot be called for something not a TextWindow"); if (tw->expired) - WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); + WSLUA_ERROR(TextWindow_prepend,"Expired TextWindow"); if (!text) WSLUA_ARG_ERROR(TextWindow_prepend,TEXT,"Must be a string"); @@ -506,11 +539,14 @@ WSLUA_METHOD TextWindow_prepend(lua_State* L) { /* Prepends text */ WSLUA_METHOD TextWindow_clear(lua_State* L) { /* Erases all text in the window. */ TextWindow tw = checkTextWindow(L,1); + if (!ops->clear_text) + WSLUA_ERROR(TextWindow_clear,"GUI not available"); + if (!tw) WSLUA_ERROR(TextWindow_clear,"Cannot be called for something not a TextWindow"); if (tw->expired) - WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); + WSLUA_ERROR(TextWindow_clear,"Expired TextWindow"); ops->clear_text(tw->ws_tw); @@ -521,11 +557,14 @@ WSLUA_METHOD TextWindow_get_text(lua_State* L) { /* Get the text of the window * TextWindow tw = checkTextWindow(L,1); const gchar* text; + if (!ops->get_text) + WSLUA_ERROR(TextWindow_get_text,"GUI not available"); + if (!tw) WSLUA_ERROR(TextWindow_get_text,"Cannot be called for something not a TextWindow"); if (tw->expired) - WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); + WSLUA_ERROR(TextWindow_get_text,"Expired TextWindow"); text = ops->get_text(tw->ws_tw); @@ -541,7 +580,9 @@ static int TextWindow__gc(lua_State* L) { if (!tw->expired) { tw->expired = TRUE; - ops->destroy_text_window(tw->ws_tw); + if (ops->destroy_text_window) { + ops->destroy_text_window(tw->ws_tw); + } } else { g_free(tw); } @@ -556,11 +597,14 @@ WSLUA_METHOD TextWindow_set_editable(lua_State* L) { /* Make this window editabl TextWindow tw = checkTextWindow(L,1); gboolean editable = wslua_optbool(L,WSLUA_OPTARG_TextWindow_set_editable_EDITABLE,TRUE); + if (!ops->set_editable) + WSLUA_ERROR(TextWindow_set_editable,"GUI not available"); + if (!tw) WSLUA_ERROR(TextWindow_set_editable,"Cannot be called for something not a TextWindow"); if (tw->expired) - WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); + WSLUA_ERROR(TextWindow_set_editable,"Expired TextWindow"); if (ops->set_editable) ops->set_editable(tw->ws_tw,editable); @@ -610,11 +654,14 @@ WSLUA_METHOD TextWindow_add_button(lua_State* L) { funnel_bt_t* fbt; wslua_bt_cb_t* cbd; + if (!ops->add_button) + WSLUA_ERROR(TextWindow_add_button,"GUI not available"); + if (!tw) WSLUA_ERROR(TextWindow_add_button,"Cannot be called for something not a TextWindow"); if (tw->expired) - WSLUA_ARG_ERROR(TextWindow_set,TEXT,"Expired TextWindow"); + WSLUA_ERROR(TextWindow_add_button,"Expired TextWindow"); if (! lua_isfunction(L,WSLUA_ARG_TextWindow_add_button_FUNCTION) ) WSLUA_ARG_ERROR(TextWindow_add_button,FUNCTION,"must be a function"); @@ -678,7 +725,7 @@ WSLUA_FUNCTION wslua_retap_packets(lua_State* L) { if ( ops->retap_packets ) { ops->retap_packets(); } else { - WSLUA_ERROR(wslua_retap_packets, "Does not work on TShark"); + WSLUA_ERROR(wslua_retap_packets, "GUI not available"); } return 0; @@ -690,7 +737,7 @@ WSLUA_FUNCTION wslua_copy_to_clipboard(lua_State* L) { /* Copy a string into the 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"); + WSLUA_ERROR(copy_to_clipboard, "GUI not available"); } if (!copied_str) { @@ -715,7 +762,7 @@ WSLUA_FUNCTION wslua_open_capture_file(lua_State* L) { /* Open and display a cap const char* error = NULL; if (!ops->open_file) { - WSLUA_ERROR(wslua_open_capture_file, "Does not work on TShark"); + WSLUA_ERROR(open_capture_file, "GUI not available"); } if (!fname) { @@ -742,7 +789,7 @@ WSLUA_FUNCTION wslua_set_filter(lua_State* L) { /* Set the main filter 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"); + WSLUA_ERROR(set_filter, "GUI not available"); } if (!filter_str) { @@ -756,7 +803,7 @@ WSLUA_FUNCTION wslua_set_filter(lua_State* L) { /* Set the main filter text */ WSLUA_FUNCTION wslua_apply_filter(lua_State* L) { /* Apply the filter in the main filter box */ if (!ops->apply_filter) { - WSLUA_ERROR(wslua_apply_filter, "Does not work on TShark"); + WSLUA_ERROR(apply_filter, "GUI not available"); } ops->apply_filter(); @@ -768,7 +815,7 @@ WSLUA_FUNCTION wslua_apply_filter(lua_State* L) { /* Apply the filter in the mai WSLUA_FUNCTION wslua_reload(lua_State* L) { /* Reload the current capture file */ if (!ops->reload) { - WSLUA_ERROR(wslua_reload, "Does not work on TShark"); + WSLUA_ERROR(reload, "GUI not available"); } ops->reload(); @@ -782,7 +829,7 @@ WSLUA_FUNCTION wslua_browser_open_url(lua_State* L) { /* Open an url in a browse const char* url = luaL_checkstring(L,WSLUA_ARG_browser_open_url_URL); if (!ops->browser_open_url) { - WSLUA_ERROR(browser_open_url, "Does not work on TShark"); + WSLUA_ERROR(browser_open_url, "GUI not available"); } if (!url) { @@ -799,7 +846,7 @@ WSLUA_FUNCTION wslua_browser_open_data_file(lua_State* L) { /* Open an file in a const char* file = luaL_checkstring(L,WSLUA_ARG_browser_open_data_file_FILENAME); if (!ops->browser_open_data_file) { - WSLUA_ERROR(browser_open_data_file, "Does not work on TShark"); + WSLUA_ERROR(browser_open_data_file, "GUI not available"); } if (!file) { |