コード例 #1
0
ファイル: testque.c プロジェクト: strongliang/C-study
int main( )
{
    Queue Q;
    int i;

    Q = CreateQueue( 12 );

    FAIL_ON_NULL(Q->data)
    
    i=0;
    for( i = 0; i < 10; i++ )
        Enqueue( i, Q );

    while( !IsEmpty( Q ) )
    {
        printf( "%d\n", Front( Q ) );
        Dequeue( Q );
    }
    for( i = 0; i < 20; i++ )
        Enqueue( i, Q );

    while( !IsEmpty( Q ) )
    {
        printf( "%d\n", Front( Q ) );
        Dequeue( Q );
    }

    DisposeQueue( Q );
    return 0;
}
コード例 #2
0
ファイル: llist.c プロジェクト: strongliang/C-study
void Delete(List *L, Position P)
{
    Position prevP; 
    Position nextP; 

    FAIL_ON_NULL(P)

    prevP = P->prev;
    nextP = P->next;

    if (!IsEmpty(prevP)) prevP->next = nextP;
    if (!IsEmpty(nextP)) nextP->prev = prevP;

    if (L && Advance(*L) == NULL && *L == P) {
        *L = NULL;
    } else if (L && *L==P) {
        *L = nextP;
    }

    free(P);
}
コード例 #3
0
ファイル: wslua_proto_expert.c プロジェクト: DHODoS/wireshark
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"

#include "wslua.h"


/* WSLUA_CONTINUE_MODULE Proto */


WSLUA_CLASS_DEFINE(ProtoExpert,FAIL_ON_NULL("null ProtoExpert"));
    /* A Protocol expert info field, to be used when adding items to the dissection tree.

       @since 1.11.3
     */

WSLUA_CONSTRUCTOR ProtoExpert_new(lua_State* L) {
    /* Creates a new `ProtoExpert` object to be used for a protocol's expert information notices.

       @since 1.11.3
     */
#define WSLUA_ARG_ProtoExpert_new_ABBR 1 /* Filter name of the expert info field (the string that
                                            is used in filters). */
#define WSLUA_ARG_ProtoExpert_new_TEXT 2 /* The default text of the expert field. */
#define WSLUA_ARG_ProtoExpert_new_GROUP 3 /* Expert group type: one of: `expert.group.CHECKSUM`,
                                             `expert.group.SEQUENCE`, `expert.group.RESPONSE_CODE`,
コード例 #4
0
ファイル: wslua_proto_field.c プロジェクト: CharaD7/wireshark
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"

#include "wslua.h"


/* WSLUA_CONTINUE_MODULE Proto */


WSLUA_CLASS_DEFINE(ProtoField,FAIL_ON_NULL("null ProtoField"),NOP);
    /* A Protocol field (to be used when adding items to the dissection tree). */

static const wslua_ft_types_t ftenums[] = {
    {"ftypes.NONE", FT_NONE},
    {"ftypes.BOOLEAN", FT_BOOLEAN},
    {"ftypes.UINT8", FT_UINT8},
    {"ftypes.UINT16", FT_UINT16},
    {"ftypes.UINT24", FT_UINT24},
    {"ftypes.UINT32", FT_UINT32},
    {"ftypes.UINT64", FT_UINT64},
    {"ftypes.INT8", FT_INT8},
    {"ftypes.INT16", FT_INT16},
    {"ftypes.INT24", FT_INT24},
    {"ftypes.INT32", FT_INT32},
    {"ftypes.INT64", FT_INT64},
コード例 #5
0
    {"__gc", Address__gc },
    {"__tostring", Address__tostring },
    {"__eq",Address__eq},
    {"__le",Address__le},
    {"__lt",Address__lt},
    {0,0}
};


int Address_register(lua_State *L) {
    WSLUA_REGISTER_CLASS(Address);
    return 1;
}


WSLUA_CLASS_DEFINE(Column,FAIL_ON_NULL("expired column"),NOP); /* A Column in the packet list */

struct col_names_t {
    const gchar* name;
    int id;
};

static const struct col_names_t colnames[] = {
    {"number",COL_NUMBER},
    {"abs_time",COL_ABS_TIME},
    {"utc_time",COL_UTC_TIME},
    {"cls_time",COL_CLS_TIME},
    {"rel_time",COL_REL_TIME},
    {"date",COL_ABS_DATE_TIME},
    {"utc_date",COL_UTC_DATE_TIME},
    {"delta_time",COL_DELTA_TIME},
コード例 #6
0
ファイル: wslua_pinfo.c プロジェクト: mACH1VO/wireshark
Pinfo* push_Pinfo(lua_State* L, packet_info* ws_pinfo) {
    Pinfo pinfo = NULL;
    if (ws_pinfo) {
        pinfo = (Pinfo)g_malloc(sizeof(struct _wslua_pinfo));
        pinfo->ws_pinfo = ws_pinfo;
        pinfo->expired = FALSE;
        g_ptr_array_add(outstanding_Pinfo,pinfo);
    }
    return pushPinfo(L,pinfo);
}

#define PUSH_COLUMN(L,c) {g_ptr_array_add(outstanding_Column,c);pushColumn(L,c);}
#define PUSH_COLUMNS(L,c) {g_ptr_array_add(outstanding_Columns,c);pushColumns(L,c);}
#define PUSH_PRIVATE_TABLE(L,c) {g_ptr_array_add(outstanding_PrivateTable,c);pushPrivateTable(L,c);}

WSLUA_CLASS_DEFINE(NSTime,FAIL_ON_NULL("NSTime"),NOP);
	/* NSTime represents a nstime_t.  This is an object with seconds and nanoseconds. */

WSLUA_CONSTRUCTOR NSTime_new(lua_State *L) {
	/* Creates a new NSTime object. */
#define WSLUA_OPTARG_NSTime_new_SECONDS 1 /* Seconds. */
#define WSLUA_OPTARG_NSTime_new_NSECONDS 2 /* Nano seconds. */
    NSTime nstime = (NSTime)g_malloc(sizeof(nstime_t));

    if (!nstime) return 0;

    nstime->secs = (time_t) luaL_optint(L,WSLUA_OPTARG_NSTime_new_SECONDS,0);
    nstime->nsecs = luaL_optint(L,WSLUA_OPTARG_NSTime_new_NSECONDS,0);

    pushNSTime(L,nstime);
コード例 #7
0
ファイル: wslua_tvb.c プロジェクト: AndresVelasco/wireshark
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"

#include <epan/emem.h>

/* WSLUA_MODULE Tvb Functions for handling packet data */

#include "wslua.h"

WSLUA_CLASS_DEFINE(ByteArray,FAIL_ON_NULL("null bytearray"),NOP);

WSLUA_CONSTRUCTOR ByteArray_new(lua_State* L) { /* Creates a ByteArray Object */
#define WSLUA_OPTARG_ByteArray_new_HEXBYTES 1 /* A string consisting of hexadecimal bytes like "00 B1 A2" or "1a2b3c4d" */
    GByteArray* ba = g_byte_array_new();
    const gchar* s;
    int nibble[2];
    int i = 0;
    gchar c;

    if (lua_gettop(L) == 1) {
        s = luaL_checkstring(L,WSLUA_OPTARG_ByteArray_new_HEXBYTES);

        if (!s)
            WSLUA_OPTARG_ERROR(ByteArray_new,HEXBYTES,"must be a string");
コード例 #8
0
ファイル: wslua_listener.c プロジェクト: wireshark/wireshark
 * (c) 2006, Luis E. Garcia Ontanon <*****@*****.**>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <*****@*****.**>
 * Copyright 1998 Gerald Combs
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

/* WSLUA_MODULE Listener Post-dissection packet analysis */

#include "wslua.h"

WSLUA_CLASS_DEFINE(Listener,FAIL_ON_NULL("Listener"));
/*
    A `Listener` is called once for every packet that matches a certain filter or has a certain tap.
    It can read the tree, the packet's `Tvb` buffer as well as the tapped data, but it cannot
    add elements to the tree.
 */

static int tap_packet_cb_error_handler(lua_State* L) {
    const gchar* error =  lua_tostring(L,1);
    static gchar* last_error = NULL;
    static int repeated = 0;
    static int next = 2;
    gchar* where =  (lua_pinfo) ?
        wmem_strdup_printf(NULL, "Lua: on packet %i Error During execution of Listener Packet Callback",lua_pinfo->num) :
        wmem_strdup_printf(NULL, "Lua: Error During execution of Listener Packet Callback") ;
コード例 #9
0
ファイル: wslua_nstime.c プロジェクト: HeartFlying/wireshark
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include "wslua.h"
#include <wsutil/nstime.h>

/* 1s = 10^9 ns. */
#define NS_PER_S 1000000000

/* WSLUA_CONTINUE_MODULE Pinfo */


WSLUA_CLASS_DEFINE(NSTime,FAIL_ON_NULL("NSTime"));
/* NSTime represents a nstime_t.  This is an object with seconds and nanoseconds. */

WSLUA_CONSTRUCTOR NSTime_new(lua_State *L) {
    /* Creates a new NSTime object. */
#define WSLUA_OPTARG_NSTime_new_SECONDS 1 /* Seconds. */
#define WSLUA_OPTARG_NSTime_new_NSECONDS 2 /* Nano seconds. */
    NSTime nstime = (NSTime)g_malloc(sizeof(nstime_t));

    if (!nstime) return 0;

    nstime->secs = (time_t) luaL_optinteger(L,WSLUA_OPTARG_NSTime_new_SECONDS,0);
    nstime->nsecs = (int) luaL_optinteger(L,WSLUA_OPTARG_NSTime_new_NSECONDS,0);

    pushNSTime(L,nstime);
コード例 #10
0
ファイル: wslua_field.c プロジェクト: HeartFlying/wireshark
    found = proto_all_finfos(lua_tree->tree);

    if (found) {
        for (i=0; i<found->len; i++) {
            push_FieldInfo(L, (field_info *)g_ptr_array_index(found,i));
            items_found++;
        }

        g_ptr_array_free(found,TRUE);
    }

    return items_found;
}

WSLUA_CLASS_DEFINE(Field,FAIL_ON_NULL("Field"));
/*
   A Field extractor to to obtain field values. A `Field` object can only be created *outside* of
   the callback functions of dissectors, post-dissectors, heuristic-dissectors, and taps.

   Once created, it is used *inside* the callback functions, to generate a `FieldInfo` object.
 */

static GPtrArray* wanted_fields = NULL;
static dfilter_t* wslua_dfilter = NULL;

/* We use a fake dfilter for Lua field extractors, so that
 * epan_dissect_run() will populate the fields.  This won't happen
 * if the passed-in edt->tree is NULL, which it will be if the
 * proto_tree isn't created by epan_dissect_init().  But that's by
 * design - if shark doesn't pass in a proto_tree, it's probably for
コード例 #11
0
ファイル: wslua_dir.c プロジェクト: ARK1988/wireshark
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"

/* WSLUA_MODULE Dir Directory handling functions */

#include "wslua.h"
#include <wsutil/file_util.h>

WSLUA_CLASS_DEFINE(Dir,FAIL_ON_NULL("Dir"),NOP); /* A Directory object, as well as associated functions. */

WSLUA_CONSTRUCTOR Dir_make(lua_State* L) {
    /* Creates a directory.

       The created directory is set for permission mode 0755 (octal), meaning it is
       read+write+execute by owner, but only read+execute by group and others.

       IF the directory was created successfully, a boolean `true` is returned.
       If the directory cannot be made because it already exists, `false` is returned.
       If the directory cannot be made because an error occurred, `nil` is returned.

       @since 1.11.3
    */
#define WSLUA_ARG_Dir_make_NAME 1 /* The name of the directory, possibly including path. */
コード例 #12
0
ファイル: wslua_tvb.c プロジェクト: jelmer/wireshark
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"

#include <epan/emem.h>

/* WSLUA_MODULE Tvb Functions for handling packet data */

#include "wslua.h"
#include "wsutil/base64.h"

WSLUA_CLASS_DEFINE(ByteArray,FAIL_ON_NULL("ByteArray"),NOP);

WSLUA_CONSTRUCTOR ByteArray_new(lua_State* L) { /* Creates a ByteArray Object */
#define WSLUA_OPTARG_ByteArray_new_HEXBYTES 1 /* A string consisting of hexadecimal bytes like "00 B1 A2" or "1a2b3c4d" */
#define WSLUA_OPTARG_ByteArray_new_SEPARATOR 2 /* A string separator between hex bytes/words (default=" "); or if the boolean value 'true' is used, then the first arg is treated as raw binary data */
    GByteArray* ba = g_byte_array_new();
    const gchar* s;
    size_t len = 0;
    const gchar* sep = " ";
    gboolean ishex = TRUE;

    if (lua_gettop(L) >= 1) {
        s = luaL_checklstring(L,WSLUA_OPTARG_ByteArray_new_HEXBYTES,&len);

        if (!s) {
            WSLUA_OPTARG_ERROR(ByteArray_new,HEXBYTES,"must be a string");
コード例 #13
0
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include "config.h"

#include "wslua.h"
#include "wsutil/base64.h"


/* WSLUA_CONTINUE_MODULE Tvb */


WSLUA_CLASS_DEFINE(ByteArray,FAIL_ON_NULL("ByteArray"),NOP);

WSLUA_CONSTRUCTOR ByteArray_new(lua_State* L) {
    /* Creates a `ByteArray` object.

       Starting in version 1.11.3, if the second argument is a boolean `true`,
       then the first argyument is treated as a raw Lua string of bytes to use,
       instead of a hexadecimal string.
     */
#define WSLUA_OPTARG_ByteArray_new_HEXBYTES 1 /* A string consisting of hexadecimal bytes like "00 B1 A2" or "1a2b3c4d". */
#define WSLUA_OPTARG_ByteArray_new_SEPARATOR 2 /* A string separator between hex bytes/words (default=" "),
                                                  or if the boolean value `true` is used, then the first argument
                                                  is treated as raw binary data */
    GByteArray* ba = g_byte_array_new();
    const gchar* s;
    size_t len = 0;
コード例 #14
0
ファイル: wslua_tvb.c プロジェクト: DHODoS/wireshark
    WSLUA_CLASS_MTREG(Tvb,eq),
    WSLUA_CLASS_MTREG(Tvb,tostring),
    {"__call", Tvb_range},
    { NULL, NULL }
};

int Tvb_register(lua_State* L) {
    WSLUA_REGISTER_CLASS(Tvb);
    outstanding_Tvb = g_ptr_array_new();
    return 0;
}




WSLUA_CLASS_DEFINE(TvbRange,FAIL_ON_NULL("TvbRange"));
/*
  A `TvbRange` represents a usable range of a `Tvb` and is used to extract data from the `Tvb` that generated it.

  `TvbRange`s are created by calling a `Tvb` (e.g. 'tvb(offset,length)'). If the `TvbRange` span is outside the
  `Tvb`'s range the creation will cause a runtime error.
 */


static void free_TvbRange(TvbRange tvbr) {
    if (!(tvbr && tvbr->tvb)) return;

    if (!tvbr->tvb->expired) {
        tvbr->tvb->expired = TRUE;
    } else {
        free_Tvb(tvbr->tvb);
コード例 #15
0
ファイル: ldlua_meta.c プロジェクト: Frank-KunLi/l7detect
#include <arpa/inet.h>
#include <stdlib.h>
#include "common.h"
#include "parser.h"
#include "ldlua.h"
#include "engine_comm.h"
#include "meta_buf.h"

LDLUA_METHOD meta_add_uint(lua_State* L);
LDLUA_METHOD meta_add_ff(lua_State* L);
LDLUA_METHOD meta_gc(lua_State *L);

LDLUA_CLASS_DEFINE(meta,FAIL_ON_NULL("LUA_META"),NOP);

extern uint32_t lde_engine_id;

static const luaL_reg meta_methods[] = {
	{"add_uint", meta_add_uint},
    {"add_ff", meta_add_ff},
    { NULL, NULL },
};

static const luaL_reg meta_meta[] = {
	{"__gc", meta_gc},
    { NULL, NULL },
};

meta* push_meta_to_stack(lua_State* L, meta s) {
    return push_meta(L, s);
}