Skip to content

Commit bbcc6ef

Browse files
authored
Merge pull request #1226 from jan-cerny/seap_move
Move SEAP out of public API
2 parents 21b8f02 + 9f96603 commit bbcc6ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+259
-537
lines changed

src/OVAL/oval_probe_ext.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
#include <config.h>
2424
#endif
2525

26-
#include <seap.h>
26+
#include "_seap.h"
2727
#include <stdarg.h>
2828
#include <string.h>
2929
#include <errno.h>

src/OVAL/oval_probe_ext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#ifndef OVAL_PROBE_EXT_H
2323
#define OVAL_PROBE_EXT_H
2424

25-
#include <seap.h>
25+
#include "_seap.h"
2626
#include <pthread.h>
2727
#include <stdbool.h>
2828
#include "oval_probe_impl.h"

src/OVAL/oval_probe_impl.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
#ifndef OVAL_PROBE_IMPL_H
3333
#define OVAL_PROBE_IMPL_H
3434

35-
#include <seap-types.h>
3635
#include "oval_definitions_impl.h"
3736
#include "oval_agent_api_impl.h"
3837
#include "oval_parser_impl.h"

src/OVAL/oval_sexp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#include <inttypes.h>
4040
#include <stdlib.h>
4141
#include <string.h>
42-
#include <seap.h>
42+
#include "_seap.h"
4343
#include <assert.h>
4444

4545
#include "oval_probe_impl.h"

src/OVAL/oval_sexp.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
#ifndef OVAL_SEXP_H
3535
#define OVAL_SEXP_H
3636

37-
#include <seap.h>
37+
#include "_seap.h"
3838
#include "../common/util.h"
3939
#include "oval_definitions_impl.h"
4040

src/OVAL/probes/SEAP/_seap-command.h

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@
2828
#include <stddef.h>
2929
#include <pthread.h>
3030

31-
#include "public/seap-command.h"
3231
#include "_sexp-types.h"
32+
#include "_seap-types.h"
3333
#include "../../../common/util.h"
3434

3535

36-
typedef uint8_t SEAP_cmdclass_t;
37-
3836
#define SEAP_CMDCLASS_INT 1
3937
#define SEAP_CMDCLASS_USR 2
4038

@@ -43,6 +41,21 @@ typedef uint8_t SEAP_cmdclass_t;
4341
#define SEAP_CMDFLAG_REPLY 0x02
4442
#define SEAP_CMDFLAG_MASK 0xff
4543

44+
#define SEAP_CMDTYPE_SYNC 1
45+
#define SEAP_CMDTYPE_ASYNC 2
46+
47+
#define SEAP_CMDREG_LOCAL 0x00000001
48+
#define SEAP_CMDREG_USEARG 0x00000002
49+
#define SEAP_CMDREG_THREAD 0x00000004
50+
51+
#define SEAP_EXEC_LOCAL 0x01
52+
#define SEAP_EXEC_LONLY 0x02
53+
#define SEAP_EXEC_GFIRST 0x04
54+
#define SEAP_EXEC_THREAD 0x08
55+
#define SEAP_EXEC_WQUEUE 0x10
56+
#define SEAP_EXEC_RECV 0x20
57+
58+
4659
struct SEAP_cmd {
4760
SEAP_cmdid_t id;
4861
SEAP_cmdid_t rid;
@@ -51,6 +64,7 @@ struct SEAP_cmd {
5164
SEAP_cmdcode_t code;
5265
SEXP_t *args;
5366
};
67+
typedef struct SEAP_cmd SEAP_cmd_t;
5468

5569
struct SEAP_synchelper {
5670
SEXP_t *args;
@@ -62,15 +76,6 @@ struct SEAP_synchelper {
6276
#define SEAP_CMDTBL_LARGE 0x01
6377
#define SEAP_CMDTBL_LARGE_TRESHOLD 32
6478

65-
typedef struct {
66-
uint8_t flags;
67-
void *table;
68-
size_t maxcnt;
69-
#if defined(SEAP_THREAD_SAFE)
70-
pthread_rwlock_t lock;
71-
#endif
72-
} SEAP_cmdtbl_t;
73-
7479
typedef struct {
7580
SEAP_cmdcode_t code;
7681
SEAP_cmdfn_t func;
@@ -96,8 +101,6 @@ int SEAP_cmdtbl_cmp (SEAP_cmdrec_t *a, SEAP_cmdrec_t *b);
96101
SEAP_cmdrec_t *SEAP_cmdrec_new (void);
97102
void SEAP_cmdrec_free (SEAP_cmdrec_t *r);
98103

99-
typedef uint8_t SEAP_cflags_t;
100-
101104
#define SEAP_CFLG_THREAD 0x01
102105
#define SEAP_CFLG_WATCH 0x02
103106

@@ -115,5 +118,15 @@ void SEAP_cmdjob_free (SEAP_cmdjob_t *j);
115118

116119
SEXP_t *SEAP_cmd2sexp (SEAP_cmd_t *cmd);
117120

121+
int SEAP_cmd_register(SEAP_CTX_t *ctx, SEAP_cmdcode_t code, uint32_t flags, SEAP_cmdfn_t func, ...);
122+
123+
SEXP_t *SEAP_cmd_exec(SEAP_CTX_t *ctx,
124+
int sd,
125+
uint32_t flags,
126+
SEAP_cmdcode_t code,
127+
SEXP_t *args,
128+
SEAP_cmdtype_t type,
129+
SEAP_cmdfn_t func,
130+
void *funcarg);
118131

119132
#endif /* _SEAP_COMMAND_H */

src/OVAL/probes/SEAP/_seap-error.h

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,19 @@
2626

2727
#include "public/sexp.h"
2828
#include "_seap-message.h"
29-
#include "public/seap-error.h"
3029
#include "../../../common/util.h"
3130

32-
/*
3331
struct SEAP_err {
34-
SEAP_msgid_t id;
35-
uint32_t code;
36-
uint8_t type;
37-
SEXP_t *data;
32+
SEAP_msgid_t id;
33+
uint32_t code;
34+
uint8_t type;
35+
SEXP_t *data;
3836
};
39-
*/
37+
38+
typedef struct SEAP_err SEAP_err_t;
39+
40+
SEAP_err_t *SEAP_error_new(void);
41+
SEAP_err_t *SEAP_error_clone(SEAP_err_t *e);
42+
void SEAP_error_free(SEAP_err_t *e);
4043

4144
#endif /* _SEAP_ERROR_H */

src/OVAL/probes/SEAP/_seap-message.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,41 @@
2626

2727
#include <stdint.h>
2828
#include "public/sexp-types.h"
29-
#include "public/seap-message.h"
3029
#include "../../../common/util.h"
3130

31+
#if SEAP_MSGID_BITS == 64
32+
typedef uint64_t SEAP_msgid_t;
33+
#else
34+
typedef uint32_t SEAP_msgid_t;
35+
#endif
3236

3337
struct SEAP_attr {
3438
char *name;
3539
SEXP_t *value;
3640
};
3741

42+
typedef struct SEAP_attr SEAP_attr_t;
43+
3844
struct SEAP_msg {
3945
SEAP_msgid_t id;
4046
SEAP_attr_t *attrs;
4147
uint16_t attrs_cnt;
4248
SEXP_t *sexp;
4349
};
4450

51+
typedef struct SEAP_msg SEAP_msg_t;
52+
53+
SEAP_msg_t *SEAP_msg_new(void);
54+
SEAP_msg_t *SEAP_msg_clone(SEAP_msg_t *msg);
55+
void SEAP_msg_free(SEAP_msg_t *msg);
56+
57+
SEAP_msgid_t SEAP_msg_id(SEAP_msg_t *msg);
58+
59+
int SEAP_msg_set(SEAP_msg_t *msg, SEXP_t *sexp);
60+
void SEAP_msg_unset(SEAP_msg_t *msg);
61+
SEXP_t *SEAP_msg_get(SEAP_msg_t *msg);
62+
63+
int SEAP_msgattr_set(SEAP_msg_t *msg, const char *name, SEXP_t *value);
64+
bool SEAP_msgattr_exists(SEAP_msg_t *msg, const char *name);
4565

4666
#endif /* _SEAP_MESSAGE_H */

src/OVAL/probes/SEAP/_seap-packet.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include "_seap-message.h"
2929
#include "_seap-command.h"
3030
#include "_seap-error.h"
31-
#include "public/seap-packet.h"
3231
#include "../../../common/util.h"
3332

3433

@@ -37,6 +36,12 @@
3736
#define SEAP_SYM_CMD SEAP_SYM_PREFIX"cmd"
3837
#define SEAP_SYM_ERR SEAP_SYM_PREFIX"err"
3938

39+
#define SEAP_PACKET_INV 0x00 /* Invalid packet */
40+
#define SEAP_PACKET_MSG 0x01 /* Message packet */
41+
#define SEAP_PACKET_ERR 0x02 /* Error packet */
42+
#define SEAP_PACKET_CMD 0x03 /* Command packet */
43+
#define SEAP_PACKET_RAW 0x04 /* Raw packet */
44+
4045
struct SEAP_packet {
4146
uint8_t type;
4247
union {
@@ -45,6 +50,21 @@ struct SEAP_packet {
4550
SEAP_cmd_t cmd;
4651
} data;
4752
};
53+
typedef struct SEAP_packet SEAP_packet_t;
54+
55+
SEAP_packet_t *SEAP_packet_new(void);
56+
void SEAP_packet_free(SEAP_packet_t *packet);
57+
58+
void *SEAP_packet_settype(SEAP_packet_t *packet, uint8_t type);
59+
uint8_t SEAP_packet_gettype(SEAP_packet_t *packet);
60+
61+
SEAP_msg_t *SEAP_packet_msg(SEAP_packet_t *packet);
62+
SEAP_cmd_t *SEAP_packet_cmd(SEAP_packet_t *packet);
63+
SEAP_err_t *SEAP_packet_err(SEAP_packet_t *packet);
4864

65+
int SEAP_packet_recv(SEAP_CTX_t *ctx, int sd, SEAP_packet_t **packet);
66+
int SEAP_packet_recv_bytype(SEAP_CTX_t *ctx, int sd, SEAP_packet_t **packet, uint8_t type);
67+
int SEAP_packet_send(SEAP_CTX_t *ctx, int sd, SEAP_packet_t *packet);
68+
int SEAP_packet_enqueue(SEAP_CTX_t *ctx, int sd, SEAP_packet_t *packet);
4969

5070
#endif /* _SEAP_PACKET_H */

src/OVAL/probes/SEAP/_seap-types.h

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,27 @@
2525
#define _SEAP_TYPES_H
2626

2727
#include <stdint.h>
28-
#include "public/seap-types.h"
2928
#include "_sexp-types.h"
30-
#include "_seap-command.h"
31-
#include "seap-descriptor.h"
3229
#include "../../../common/util.h"
30+
#include "generic/rbt/rbt_common.h"
31+
#include "generic/bitmap.h"
32+
#include "oval_types.h"
3333

34+
typedef uint8_t SEAP_cflags_t;
35+
36+
typedef struct {
37+
rbt_t *tree;
38+
bitmap_t *bmap;
39+
} SEAP_desctable_t;
40+
41+
typedef struct {
42+
uint8_t flags;
43+
void *table;
44+
size_t maxcnt;
45+
#if defined(SEAP_THREAD_SAFE)
46+
pthread_rwlock_t lock;
47+
#endif
48+
} SEAP_cmdtbl_t;
3449

3550
/* SEAP context */
3651
struct SEAP_CTX {
@@ -44,6 +59,35 @@ struct SEAP_CTX {
4459
uint16_t send_timeout;
4560
oval_subtype_t subtype;
4661
};
62+
typedef struct SEAP_CTX SEAP_CTX_t;
63+
64+
typedef uint8_t SEAP_cmdclass_t;
65+
typedef uint16_t SEAP_cmdcode_t;
66+
typedef uint16_t SEAP_cmdid_t;
67+
typedef uint8_t SEAP_cmdtype_t;
68+
typedef SEXP_t * (*SEAP_cmdfn_t) (SEXP_t *, void *);
69+
70+
#define SEAP_CTX_INITIALIZER { NULL, 0, 0, 0, SEAP_DESCTBL_INITIALIZER, SEAP_CMDTABLE_INITIALIZER }
71+
72+
/* SEAP errors */
73+
#define SEAP_ETYPE_INT 0 /* Internal error */
74+
#define SEAP_ETYPE_USER 1 /* User-defined error */
75+
76+
#define SEAP_EUNFIN 1 /* Can't finish parsing */
77+
#define SEAP_EPARSE 2 /* Parsing error */
78+
#define SEAP_ECLOSE 3 /* Connection close */
79+
#define SEAP_EINVAL 4 /* Invalid argument */
80+
#define SEAP_ENOMEM 5 /* Cannot allocate memory */
81+
#define SEAP_EMSEXP 6 /* Missing required S-exp/value */
82+
#define SEAP_EMATTR 7 /* Missing required attribute */
83+
#define SEAP_EUNEXP 8 /* Unexpected error */
84+
#define SEAP_EUSER 9 /* User-defined error */
85+
#define SEAP_ENOCMD 10 /* Unknown cmd */
86+
#define SEAP_EQFULL 11 /* Queue full */
87+
#define SEAP_EUNKNOWN 255 /* Unknown/Unexpected error */
4788

89+
/* SEAP I/O flags */
90+
#define SEAP_IOFL_RECONN 0x00000001 /* Try to reconnect */
91+
#define SEAP_IOFL_NONBLOCK 0x00000002 /* Non-blocking mode */
4892

4993
#endif /* _SEAP_TYPES_H */

0 commit comments

Comments
 (0)