Fix up indentation to get it consistent and other minor cleanup issues.

svn path=/trunk/; revision=34598
This commit is contained in:
Jeff Morriss 2010-10-21 00:54:58 +00:00
parent 30ab866b25
commit f3648fc66d
1 changed files with 163 additions and 146 deletions

View File

@ -33,7 +33,7 @@
WSLUA_CLASS_DEFINE(PseudoHeader,NOP,NOP);
/*
A pseudoheader to be used to save captured frames.
* A pseudoheader to be used to save captured frames.
*/
enum lua_pseudoheader_type {
@ -54,27 +54,30 @@ enum lua_pseudoheader_type {
struct lua_pseudo_header {
enum lua_pseudoheader_type type;
union wtap_pseudo_header* wph;
union wtap_pseudo_header *wph;
};
WSLUA_CONSTRUCTOR PseudoHeader_none(lua_State* L) {
WSLUA_CONSTRUCTOR
PseudoHeader_none(lua_State *L)
{
/*
Creates a "no" pseudoheader.
* Creates a "no" pseudoheader.
*
*/
PseudoHeader ph = g_malloc(sizeof(struct lua_pseudo_header));
ph->type = PHDR_NONE;
ph->wph = NULL;
pushPseudoHeader(L,ph);
WSLUA_RETURN(1);
/* A null pseudoheader */
WSLUA_RETURN(1); /* A null pseudoheader */
}
WSLUA_CONSTRUCTOR PseudoHeader_eth(lua_State* L) {
WSLUA_CONSTRUCTOR
PseudoHeader_eth(lua_State *L)
{
/*
Creates an ethernet pseudoheader
* Creates an ethernet pseudoheader
*/
#define WSLUA_OPTARG_PseudoHeader_eth_FCSLEN 1 /* The fcs length */
@ -89,9 +92,11 @@ WSLUA_CONSTRUCTOR PseudoHeader_eth(lua_State* L) {
WSLUA_RETURN(1); /* The ethernet pseudoheader */
}
WSLUA_CONSTRUCTOR PseudoHeader_atm(lua_State* L) {
WSLUA_CONSTRUCTOR
PseudoHeader_atm(lua_State *L)
{
/*
Creates an ATM pseudoheader
* Creates an ATM pseudoheader
*/
#define WSLUA_OPTARG_PseudoHeader_atm_AAL 1 /* AAL number */
#define WSLUA_OPTARG_PseudoHeader_atm_VPI 2 /* VPI */
@ -113,11 +118,12 @@ WSLUA_CONSTRUCTOR PseudoHeader_atm(lua_State* L) {
ph->wph->atm.aal5t_len = luaL_optint(L,WSLUA_OPTARG_PseudoHeader_atm_AAL5LEN,0);
pushPseudoHeader(L,ph);
WSLUA_RETURN(1);
/* The ATM pseudoheader */
WSLUA_RETURN(1); /* The ATM pseudoheader */
}
WSLUA_CONSTRUCTOR PseudoHeader_mtp2(lua_State* L) {
WSLUA_CONSTRUCTOR
PseudoHeader_mtp2(lua_State *L)
{
/* Creates an MTP2 PseudoHeader */
#define WSLUA_OPTARG_PseudoHeader_mtp2_SENT 1 /* True if the packet is sent, False if received. */
#define WSLUA_OPTARG_PseudoHeader_mtp2_ANNEXA 2 /* True if annex A is used */
@ -134,14 +140,14 @@ WSLUA_CONSTRUCTOR PseudoHeader_mtp2(lua_State* L) {
}
#if 0
static int PseudoHeader_x25(lua_State* L) { luaL_error(L,"not implemented"); return 0; }
static int PseudoHeader_isdn(lua_State* L) { luaL_error(L,"not implemented"); return 0; }
static int PseudoHeader_ascend(lua_State* L) { luaL_error(L,"not implemented"); return 0; }
static int PseudoHeader_wifi(lua_State* L) { luaL_error(L,"not implemented"); return 0; }
static int PseudoHeader_cosine(lua_State* L) { luaL_error(L,"not implemented"); return 0; }
static int PseudoHeader_irda(lua_State* L) { luaL_error(L,"not implemented"); return 0; }
static int PseudoHeader_nettl(lua_State* L) { luaL_error(L,"not implemented"); return 0; }
static int PseudoHeader_k12(lua_State* L) { luaL_error(L,"not implemented"); return 0; }
static int PseudoHeader_x25(lua_State *L) { luaL_error(L,"not implemented"); return 0; }
static int PseudoHeader_isdn(lua_State *L) { luaL_error(L,"not implemented"); return 0; }
static int PseudoHeader_ascend(lua_State *L) { luaL_error(L,"not implemented"); return 0; }
static int PseudoHeader_wifi(lua_State *L) { luaL_error(L,"not implemented"); return 0; }
static int PseudoHeader_cosine(lua_State *L) { luaL_error(L,"not implemented"); return 0; }
static int PseudoHeader_irda(lua_State *L) { luaL_error(L,"not implemented"); return 0; }
static int PseudoHeader_nettl(lua_State *L) { luaL_error(L,"not implemented"); return 0; }
static int PseudoHeader_k12(lua_State *L) { luaL_error(L,"not implemented"); return 0; }
#endif
WSLUA_METHODS PseudoHeader_methods[] = {
@ -156,7 +162,9 @@ WSLUA_META PseudoHeader_meta[] = {
{0,0}
};
int PseudoHeader_register(lua_State* L) {
int
PseudoHeader_register(lua_State *L)
{
WSLUA_REGISTER_CLASS(PseudoHeader)
return 0;
}
@ -164,16 +172,18 @@ int PseudoHeader_register(lua_State* L) {
WSLUA_CLASS_DEFINE(Dumper,FAIL_ON_NULL("Dumper already closed"),NOP);
static GHashTable* dumper_encaps = NULL;
static GHashTable *dumper_encaps = NULL;
#define DUMPER_ENCAP(d) GPOINTER_TO_INT(g_hash_table_lookup(dumper_encaps,d))
static const char* cross_plat_fname(const char* fname) {
static const char*
cross_plat_fname(const char *fname)
{
static char fname_clean[256];
char* f;
char *f;
strncpy(fname_clean,fname,256);
for(f = fname_clean; *f; f++) {
for (f = fname_clean; *f; f++) {
switch(*f) {
case '/': case '\\':
*f = *(G_DIR_SEPARATOR_S);
@ -186,20 +196,22 @@ static const char* cross_plat_fname(const char* fname) {
return fname_clean;
}
WSLUA_CONSTRUCTOR Dumper_new(lua_State* L) {
WSLUA_CONSTRUCTOR
Dumper_new(lua_State *L)
{
/*
Creates a file to write packets.
Dumper:new_for_current() will probably be a better choice.
* Creates a file to write packets.
* Dumper:new_for_current() will probably be a better choice.
*/
#define WSLUA_ARG_Dumper_new_FILENAME 1 /* The name of the capture file to be created */
#define WSLUA_OPTARG_Dumper_new_FILETYPE 2 /* The type of the file to be created */
#define WSLUA_OPTARG_Dumper_new_ENCAP 3 /* The encapsulation to be used in the file to be created */
Dumper d;
const char* fname = luaL_checkstring(L,WSLUA_ARG_Dumper_new_FILENAME);
const char *fname = luaL_checkstring(L,WSLUA_ARG_Dumper_new_FILENAME);
int filetype = luaL_optint(L,WSLUA_OPTARG_Dumper_new_FILETYPE,WTAP_FILE_PCAP);
int encap = luaL_optint(L,WSLUA_OPTARG_Dumper_new_ENCAP,WTAP_ENCAP_ETHERNET);
int err = 0;
const char* filename;
const char *filename;
if (! fname) return 0;
@ -212,8 +224,7 @@ WSLUA_CONSTRUCTOR Dumper_new(lua_State* L) {
if (! d ) {
/* WSLUA_ERROR("Error while opening file for writing"); */
luaL_error(L,"error while opening `%s': %s",
filename,
luaL_error(L,"error while opening `%s': %s", filename,
wtap_strerror(err));
return 0;
}
@ -221,23 +232,23 @@ WSLUA_CONSTRUCTOR Dumper_new(lua_State* L) {
g_hash_table_insert(dumper_encaps,d,GINT_TO_POINTER(encap));
pushDumper(L,d);
WSLUA_RETURN(1);
/* The newly created Dumper object */
WSLUA_RETURN(1); /* The newly created Dumper object */
}
WSLUA_METHOD Dumper_close(lua_State* L) {
WSLUA_METHOD
Dumper_close(lua_State *L)
{
/* Closes a dumper */
Dumper* dp = (Dumper*)luaL_checkudata(L, 1, "Dumper");
Dumper *dp = (Dumper*)luaL_checkudata(L, 1, "Dumper");
int err;
if (! *dp)
WSLUA_ERROR(Dumper_close,"Cannot operate on a closed dumper");
g_hash_table_remove(dumper_encaps,*dp);
g_hash_table_remove(dumper_encaps, *dp);
if (!wtap_dump_close(*dp, &err)) {
luaL_error(L,"error closing: %s",
wtap_strerror(err));
luaL_error(L,"error closing: %s", wtap_strerror(err));
}
/* this way if we close a dumper any attempt to use it (for everything but GC) will yield an error */
@ -246,9 +257,11 @@ WSLUA_METHOD Dumper_close(lua_State* L) {
return 0;
}
WSLUA_METHOD Dumper_flush(lua_State* L) {
WSLUA_METHOD
Dumper_flush(lua_State *L)
{
/*
Writes all unsaved data of a dumper to the disk.
* Writes all unsaved data of a dumper to the disk.
*/
Dumper d = checkDumper(L,1);
@ -259,10 +272,12 @@ WSLUA_METHOD Dumper_flush(lua_State* L) {
return 0;
}
WSLUA_METHOD Dumper_dump(lua_State* L) {
WSLUA_METHOD
Dumper_dump(lua_State *L)
{
/*
Dumps an arbitrary packet.
Note: Dumper:dump_current() will fit best in most cases.
* Dumps an arbitrary packet.
* Note: Dumper:dump_current() will fit best in most cases.
*/
#define WSLUA_ARG_Dumper_dump_TIMESTAMP 2 /* The absolute timestamp the packet will have */
#define WSLUA_ARG_Dumper_dump_PSEUDOHEADER 3 /* The Pseudoheader to use. */
@ -294,25 +309,25 @@ WSLUA_METHOD Dumper_dump(lua_State* L) {
pkthdr.pkt_encap = DUMPER_ENCAP(d);
if (! wtap_dump(d, &pkthdr, ph->wph, ba->data, &err)) {
luaL_error(L,"error while dumping: %s",
wtap_strerror(err));
luaL_error(L,"error while dumping: %s", wtap_strerror(err));
}
return 0;
}
WSLUA_METHOD Dumper_new_for_current(lua_State* L) {
WSLUA_METHOD
Dumper_new_for_current(lua_State *L)
{
/*
Creates a capture file using the same encapsulation as the one of the cuurrent packet
* Creates a capture file using the same encapsulation as the one of the cuurrent packet
*/
#define WSLUA_OPTARG_Dumper_new_for_current_FILETYPE 2 /* The file type. Defaults to pcap. */
Dumper d;
const char* fname = luaL_checkstring(L,1);
const char *fname = luaL_checkstring(L,1);
int filetype = luaL_optint(L,WSLUA_OPTARG_Dumper_new_for_current_FILETYPE,WTAP_FILE_PCAP);
int encap;
int err = 0;
const char* filename;
const char *filename;
if (! fname) return 0;
@ -332,26 +347,26 @@ WSLUA_METHOD Dumper_new_for_current(lua_State* L) {
d = wtap_dump_open(filename, filetype, encap, 0 , FALSE, &err);
if (! d ) {
if (! d) {
luaL_error(L,"error while opening `%s': %s",
filename,
wtap_strerror(err));
filename, wtap_strerror(err));
return 0;
}
pushDumper(L,d);
WSLUA_RETURN(1); /* The newly created Dumper Object */
}
WSLUA_METHOD Dumper_dump_current(lua_State* L) {
WSLUA_METHOD
Dumper_dump_current(lua_State *L)
{
/*
Dumps the current packet as it is.
* Dumps the current packet as it is.
*/
Dumper d = checkDumper(L,1);
struct wtap_pkthdr pkthdr;
const guchar* data;
tvbuff_t* tvb;
const guchar *data;
tvbuff_t *tvb;
data_source *data_src;
int err = 0;
@ -374,15 +389,16 @@ WSLUA_METHOD Dumper_dump_current(lua_State* L) {
data = ep_tvb_memdup(tvb,0,pkthdr.caplen);
if (! wtap_dump(d, &pkthdr, lua_pinfo->pseudo_header, data, &err)) {
luaL_error(L,"error while dumping: %s",
wtap_strerror(err));
luaL_error(L,"error while dumping: %s", wtap_strerror(err));
}
return 0;
}
static int Dumper__gc(lua_State* L) {
Dumper* dp = (Dumper*)luaL_checkudata(L, 1, "Dumper");
static int
Dumper__gc(lua_State *L)
{
Dumper *dp = (Dumper*)luaL_checkudata(L, 1, "Dumper");
int err;
/* If we are Garbage Collected it means the Dumper is no longer usable. Close it */
@ -390,11 +406,10 @@ static int Dumper__gc(lua_State* L) {
if (! *dp)
return 0; /* already closed, nothing to do! */
g_hash_table_remove(dumper_encaps,*dp);
g_hash_table_remove(dumper_encaps, *dp);
if (!wtap_dump_close(*dp, &err)) {
luaL_error(L,"error closing: %s",
wtap_strerror(err));
luaL_error(L,"error closing: %s", wtap_strerror(err));
}
return 0;
@ -416,7 +431,9 @@ WSLUA_META Dumper_meta[] = {
{0, 0}
};
int Dumper_register(lua_State* L) {
int
Dumper_register(lua_State *L)
{
dumper_encaps = g_hash_table_new(g_direct_hash,g_direct_equal);
WSLUA_REGISTER_CLASS(Dumper);
return 1;