Wireshark  2.9.0-477-g68ec514b
The Wireshark network protocol analyzer
lrexlib.h
1 /* common.h */
2 /*
3 License of Lrexlib release
4 --------------------------
5 
6 Copyright (C) Reuben Thomas 2000-2012
7 Copyright (C) Shmuel Zeigerman 2004-2012
8 
9 SPDX-License-Identifier: MIT
10 */
11 
12 #ifndef _LREXLIB_H
13 #define _LREXLIB_H
14 
15 #include "lua.h"
16 
17 #define VERSION "2.7.2"
18 
19 #define LREXLIB_WIRESHARK
20 
21 #if LUA_VERSION_NUM > 501
22  int luaL_typerror (lua_State *L, int narg, const char *tname);
23 #endif
24 
25 /* REX_API can be overridden from the command line or Makefile */
26 #ifndef REX_API
27 # define REX_API LUALIB_API
28 #endif
29 
30 #ifndef REX_OPENLIB
31 # define REX_OPENLIB luaopen_rex_glib
32 #endif
33 
34 /* public function declarations */
35 REX_API int REX_OPENLIB (lua_State *L);
36 extern int Gregex_get_compile_flags (lua_State *L);
37 extern int Gregex_get_match_flags (lua_State *L);
38 extern int Gregex_get_flags (lua_State *L);
39 
40 /* Special values for maxmatch in gsub. They all must be negative. */
41 #define GSUB_UNLIMITED -1
42 #define GSUB_CONDITIONAL -2
43 
44 /* Common structs and functions */
45 
46 typedef struct {
47  const char* key;
48  int val;
49 } flag_pair;
50 
51 typedef struct { /* compile arguments */
52  const char * pattern;
53  size_t patlen;
54  void * ud;
55  int cflags;
56  const char * locale; /* PCRE, Oniguruma */
57  const unsigned char * tables; /* PCRE */
58  int tablespos; /* PCRE */
59  void * syntax; /* Oniguruma */
60  const unsigned char * translate; /* GNU */
61  int gnusyn; /* GNU */
62 } TArgComp;
63 
64 typedef struct { /* exec arguments */
65  const char * text;
66  size_t textlen;
67  int startoffset;
68  int eflags;
69  int funcpos;
70  int maxmatch;
71  int funcpos2; /* used with gsub */
72  int reptype; /* used with gsub */
73  size_t ovecsize; /* PCRE: dfa_exec */
74  size_t wscount; /* PCRE: dfa_exec */
75 } TArgExec;
76 
77 struct tagFreeList; /* forward declaration */
78 
79 struct tagBuffer {
80  size_t size;
81  size_t top;
82  char * arr;
83  lua_State * L;
84  struct tagFreeList * freelist;
85 };
86 
87 struct tagFreeList {
88  struct tagBuffer * list[16];
89  int top;
90 };
91 
92 typedef struct tagBuffer TBuffer;
93 typedef struct tagFreeList TFreeList;
94 
95 void freelist_init (TFreeList *fl);
96 void freelist_add (TFreeList *fl, TBuffer *buf);
97 void freelist_free (TFreeList *fl);
98 
99 void buffer_init (TBuffer *buf, size_t sz, lua_State *L, TFreeList *fl);
100 void buffer_free (TBuffer *buf);
101 void buffer_clear (TBuffer *buf);
102 void buffer_addbuffer (TBuffer *trg, TBuffer *src);
103 void buffer_addlstring (TBuffer *buf, const void *src, size_t sz);
104 void buffer_addvalue (TBuffer *buf, int stackpos);
105 void buffer_pushresult (TBuffer *buf);
106 
107 void bufferZ_putrepstring (TBuffer *buf, int reppos, int nsub);
108 int bufferZ_next (TBuffer *buf, size_t *iter, size_t *len, const char **str);
109 void bufferZ_addlstring (TBuffer *buf, const void *src, size_t len);
110 void bufferZ_addnum (TBuffer *buf, size_t num);
111 
112 int get_int_field (lua_State *L, const char* field);
113 void set_int_field (lua_State *L, const char* field, int val);
114 int get_flags (lua_State *L, const flag_pair **arr);
115 const char *get_flag_key (const flag_pair *fp, int val);
116 void *Lmalloc (lua_State *L, size_t size);
117 void *Lrealloc (lua_State *L, void *p, size_t osize, size_t nsize);
118 void Lfree (lua_State *L, void *p, size_t size);
119 
120 #endif
Definition: lrexlib.h:79
Definition: lrexlib.h:64
Definition: lrexlib.h:51
Definition: lrexlib.h:46
Definition: lrexlib.h:87