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 #if LUA_VERSION_NUM > 501
35 # define lua_objlen lua_rawlen
36  int luaL_typerror (lua_State *L, int narg, const char *tname);
37 #endif
38 
39 /* REX_API can be overridden from the command line or Makefile */
40 #ifndef REX_API
41 # define REX_API LUALIB_API
42 #endif
43 
44 /* Special values for maxmatch in gsub. They all must be negative. */
45 #define GSUB_UNLIMITED -1
46 #define GSUB_CONDITIONAL -2
47 
48 /* Common structs and functions */
49 
50 typedef struct {
51  const char* key;
52  int val;
53 } flag_pair;
54 
55 typedef struct { /* compile arguments */
56  const char * pattern;
57  size_t patlen;
58  void * ud;
59  int cflags;
60  const char * locale; /* PCRE, Oniguruma */
61  const unsigned char * tables; /* PCRE */
62  int tablespos; /* PCRE */
63  void * syntax; /* Oniguruma */
64  const unsigned char * translate; /* GNU */
65  int gnusyn; /* GNU */
66 } TArgComp;
67 
68 typedef struct { /* exec arguments */
69  const char * text;
70  size_t textlen;
71  int startoffset;
72  int eflags;
73  int funcpos;
74  int maxmatch;
75  int funcpos2; /* used with gsub */
76  int reptype; /* used with gsub */
77  size_t ovecsize; /* PCRE: dfa_exec */
78  size_t wscount; /* PCRE: dfa_exec */
79 } TArgExec;
80 
81 struct tagFreeList; /* forward declaration */
82 
83 struct tagBuffer {
84  size_t size;
85  size_t top;
86  char * arr;
87  lua_State * L;
88  struct tagFreeList * freelist;
89 };
90 
91 struct tagFreeList {
92  struct tagBuffer * list[16];
93  int top;
94 };
95 
96 typedef struct tagBuffer TBuffer;
97 typedef struct tagFreeList TFreeList;
98 
99 void freelist_init (TFreeList *fl);
100 void freelist_add (TFreeList *fl, TBuffer *buf);
101 void freelist_free (TFreeList *fl);
102 
103 void buffer_init (TBuffer *buf, size_t sz, lua_State *L, TFreeList *fl);
104 void buffer_free (TBuffer *buf);
105 void buffer_clear (TBuffer *buf);
106 void buffer_addbuffer (TBuffer *trg, TBuffer *src);
107 void buffer_addlstring (TBuffer *buf, const void *src, size_t sz);
108 void buffer_addvalue (TBuffer *buf, int stackpos);
109 void buffer_pushresult (TBuffer *buf);
110 
111 void bufferZ_putrepstring (TBuffer *buf, int reppos, int nsub);
112 int bufferZ_next (TBuffer *buf, size_t *iter, size_t *len, const char **str);
113 void bufferZ_addlstring (TBuffer *buf, const void *src, size_t len);
114 void bufferZ_addnum (TBuffer *buf, size_t num);
115 
116 int get_int_field (lua_State *L, const char* field);
117 void set_int_field (lua_State *L, const char* field, int val);
118 int get_flags (lua_State *L, const flag_pair **arr);
119 const char *get_flag_key (const flag_pair *fp, int val);
120 void *Lmalloc (lua_State *L, size_t size);
121 void *Lrealloc (lua_State *L, void *p, size_t osize, size_t nsize);
122 void Lfree (lua_State *L, void *p, size_t size);
123 
124 #ifndef REX_NOEMBEDDEDTEST
125 int newmembuffer (lua_State *L);
126 #endif
127 
128 #endif
Definition: common.h:55
Definition: common.h:68
Definition: common.h:50
Definition: common.h:83
Definition: common.h:91