diff --git a/epan/column-utils.c b/epan/column-utils.c index 71365dccf7..96b94f8a7c 100644 --- a/epan/column-utils.c +++ b/epan/column-utils.c @@ -165,6 +165,26 @@ col_set_fence(column_info *cinfo, const gint el) } } +/* Gets the text of a column */ +const gchar * +col_get_text(column_info *cinfo, const gint el) +{ + int i; + const gchar* text = NULL; + + if (!(cinfo && (cinfo)->col_first[el] >= 0)) { + return NULL; + } + + for (i = cinfo->col_first[el]; i <= cinfo->col_last[el]; i++) { + if (cinfo->fmt_matx[i][el]) { + text = (cinfo->col_data[i]); + } + } + return text; +} + + /* Use this to clear out a column, especially if you're going to be appending to it later; at least on some platforms, it's more efficient than using "col_add_str()" with a null string, and diff --git a/epan/column-utils.h b/epan/column-utils.h index daa7353e36..073cbc12ff 100644 --- a/epan/column-utils.h +++ b/epan/column-utils.h @@ -117,6 +117,15 @@ extern gint check_col(column_info *cinfo, const gint col); */ extern void col_set_fence(column_info *cinfo, const gint col); +/** Gets the text of a column element. + * + * @param cinfo the current packet row + * @param col the column to use, e.g. COL_INFO + * + * @return the text string + */ +extern const gchar *col_get_text(column_info *cinfo, const gint col); + /** Clears the text of a column element. * * @param cinfo the current packet row diff --git a/epan/wslua/wslua_pinfo.c b/epan/wslua/wslua_pinfo.c index cbbc335805..46146cc84b 100644 --- a/epan/wslua/wslua_pinfo.c +++ b/epan/wslua/wslua_pinfo.c @@ -604,17 +604,21 @@ static const gchar* col_id_to_name(gint id) { WSLUA_METAMETHOD Column__tostring(lua_State *L) { Column c = checkColumn(L,1); - const gchar* name; + const gchar* text; - if (!(c)) { - return 0; + if (!c) { + lua_pushstring(L,"(nil)"); + } + else if (!c->cinfo) { + text = col_id_to_name(c->col); + lua_pushfstring(L, "(%s)", text ? text : "unknown"); + } + else { + text = col_get_text(c->cinfo, c->col); + lua_pushstring(L, text ? text : "(nil)"); } - /* XXX: should return the column's text ! */ - name = col_id_to_name(c->col); - lua_pushstring(L,name ? name : "Unknown Column"); - - WSLUA_RETURN(1); /* A string representing the column */ + WSLUA_RETURN(1); /* The column's string text (in parenthesis if not available) */ } static int Column__gc(lua_State* L) { @@ -691,12 +695,24 @@ WSLUA_METHOD Column_prepend(lua_State *L) { return 0; } +WSLUA_METHOD Column_fence(lua_State *L) { + /* Sets Column text fence, to prevent overwriting */ + Column c = checkColumn(L,1); + + if (c && c->cinfo) + col_set_fence(c->cinfo, c->col); + + return 0; +} + + WSLUA_METHODS Column_methods[] = { WSLUA_CLASS_FNREG(Column,clear), WSLUA_CLASS_FNREG(Column,set), WSLUA_CLASS_FNREG(Column,append), WSLUA_CLASS_FNREG(Column,prepend), WSLUA_CLASS_FNREG_ALIAS(Column,preppend,prepend), + WSLUA_CLASS_FNREG(Column,fence), {0,0} };