Wireshark  4.3.0
The Wireshark network protocol analyzer
common.h
1 /* common.h */
2 /*
3  * Copyright (C) Reuben Thomas 2000-2020
4  * Copyright (C) Shmuel Zeigerman 2004-2020
5 
6  * Permission is hereby granted, free of charge, to any person
7  * obtaining a copy of this software and associated
8  * documentation files (the "Software"), to deal in the
9  * Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute,
11  * sublicense, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so,
13  * subject to the following conditions:
14 
15  * The above copyright notice and this permission notice shall
16  * be included in all copies or substantial portions of the
17  * Software.
18 
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
20  * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
21  * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22  * PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
23  * OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
24  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
25  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  */
28 
29 #ifndef COMMON_H
30 #define COMMON_H
31 
32 #include "lua.h"
33 
34 # define lua_objlen lua_rawlen
35  int luaL_typerror (lua_State *L, int narg, const char *tname);
36 
37 /* REX_API can be overridden from the command line or Makefile */
38 #ifndef REX_API
39 # define REX_API LUALIB_API
40 #endif
41 
42 /* Special values for maxmatch in gsub. They all must be negative. */
43 #define GSUB_UNLIMITED -1
44 #define GSUB_CONDITIONAL -2
45 
46 /* Common structs and functions */
47 
48 typedef struct {
49  const char* key;
50  int val;
51 } flag_pair;
52 
53 typedef struct { /* compile arguments */
54  const char * pattern;
55  size_t patlen;
56  void * ud;
57  int cflags;
58  const char * locale; /* PCRE, Oniguruma */
59  const unsigned char * tables; /* PCRE */
60  int tablespos; /* PCRE */
61  void * syntax; /* Oniguruma */
62  const unsigned char * translate; /* GNU */
63  int gnusyn; /* GNU */
64 } TArgComp;
65 
66 typedef struct { /* exec arguments */
67  const char * text;
68  size_t textlen;
69  int startoffset;
70  int eflags;
71  int funcpos;
72  int maxmatch;
73  int funcpos2; /* used with gsub */
74  int reptype; /* used with gsub */
75  size_t ovecsize; /* PCRE: dfa_exec */
76  size_t wscount; /* PCRE: dfa_exec */
77 } TArgExec;
78 
79 struct tagFreeList; /* forward declaration */
80 
81 struct tagBuffer {
82  size_t size;
83  size_t top;
84  char * arr;
85  lua_State * L;
86  struct tagFreeList * freelist;
87 };
88 
89 struct tagFreeList {
90  struct tagBuffer * list[16];
91  int top;
92 };
93 
94 typedef struct tagBuffer TBuffer;
95 typedef struct tagFreeList TFreeList;
96 
97 void freelist_init (TFreeList *fl);
98 void freelist_add (TFreeList *fl, TBuffer *buf);
99 void freelist_free (TFreeList *fl);
100 
101 void buffer_init (TBuffer *buf, size_t sz, lua_State *L, TFreeList *fl);
102 void buffer_free (TBuffer *buf);
103 void buffer_clear (TBuffer *buf);
104 void buffer_addbuffer (TBuffer *trg, TBuffer *src);
105 void buffer_addlstring (TBuffer *buf, const void *src, size_t sz);
106 void buffer_addvalue (TBuffer *buf, int stackpos);
107 void buffer_pushresult (TBuffer *buf);
108 
109 void bufferZ_putrepstring (TBuffer *buf, int reppos, int nsub);
110 int bufferZ_next (TBuffer *buf, size_t *iter, size_t *len, const char **str);
111 void bufferZ_addlstring (TBuffer *buf, const void *src, size_t len);
112 void bufferZ_addnum (TBuffer *buf, size_t num);
113 
114 int get_int_field (lua_State *L, const char* field);
115 void set_int_field (lua_State *L, const char* field, int val);
116 int get_flags (lua_State *L, const flag_pair **arr);
117 const char *get_flag_key (const flag_pair *fp, int val);
118 void *Lmalloc (lua_State *L, size_t size);
119 void *Lrealloc (lua_State *L, void *p, size_t osize, size_t nsize);
120 void Lfree (lua_State *L, void *p, size_t size);
121 
122 #ifndef REX_NOEMBEDDEDTEST
123 int newmembuffer (lua_State *L);
124 #endif
125 
126 #endif
Definition: common.h:53
Definition: common.h:66
Definition: common.h:48
Definition: common.h:81
Definition: common.h:89