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