Open SCAP Library
_seap-command.h
1 /*
2  * Copyright 2009 Red Hat Inc., Durham, North Carolina.
3  * All Rights Reserved.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Authors:
20  * "Daniel Kopecek" <dkopecek@redhat.com>
21  */
22 
23 #pragma once
24 #ifndef _SEAP_COMMAND_H
25 #define _SEAP_COMMAND_H
26 
27 #include <stdint.h>
28 #include <stddef.h>
29 #include <pthread.h>
30 
31 #include "public/seap-command.h"
32 #include "_sexp-types.h"
33 #include "../../../common/util.h"
34 
35 
36 typedef uint8_t SEAP_cmdclass_t;
37 
38 #define SEAP_CMDCLASS_INT 1
39 #define SEAP_CMDCLASS_USR 2
40 
41 #define SEAP_CMDFLAG_SYNC 0x01
42 #define SEAP_CMDFLAG_ASYNC 0x00
43 #define SEAP_CMDFLAG_REPLY 0x02
44 #define SEAP_CMDFLAG_MASK 0xff
45 
46 struct SEAP_cmd {
47  SEAP_cmdid_t id;
48  SEAP_cmdid_t rid;
49  uint8_t flags;
50  SEAP_cmdclass_t class;
51  SEAP_cmdcode_t code;
52  SEXP_t *args;
53 };
54 
56  SEXP_t *args;
57  pthread_cond_t cond;
58  pthread_mutex_t mtx;
59  int signaled;
60 };
61 
62 #define SEAP_CMDTBL_LARGE 0x01
63 #define SEAP_CMDTBL_LARGE_TRESHOLD 32
64 
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
73 
74 typedef struct {
75  SEAP_cmdcode_t code;
76  SEAP_cmdfn_t func;
77  void *arg;
79 
80 SEAP_cmdtbl_t *SEAP_cmdtbl_new (void);
81 void SEAP_cmdtbl_free (SEAP_cmdtbl_t *t);
82 
83 int SEAP_cmdtbl_setsize (SEAP_cmdtbl_t *t, size_t maxsz);
84 int SEAP_cmdtbl_setfl (SEAP_cmdtbl_t *t, uint8_t f);
85 int SEAP_cmdtbl_unsetfl (SEAP_cmdtbl_t *t, uint8_t f);
86 
87 /* Generic operations */
88 int SEAP_cmdtbl_add (SEAP_cmdtbl_t *t, SEAP_cmdrec_t *r);
89 int SEAP_cmdtbl_ins (SEAP_cmdtbl_t *t, SEAP_cmdrec_t *r);
90 int SEAP_cmdtbl_del (SEAP_cmdtbl_t *t, SEAP_cmdrec_t *r);
91 SEAP_cmdrec_t *SEAP_cmdtbl_get (SEAP_cmdtbl_t *t, SEAP_cmdcode_t c);
92 int SEAP_cmdtbl_cmp (SEAP_cmdrec_t *a, SEAP_cmdrec_t *b);
93 
94 #define SEAP_CMDTBL_ECOLL 1
95 
96 SEAP_cmdrec_t *SEAP_cmdrec_new (void);
97 void SEAP_cmdrec_free (SEAP_cmdrec_t *r);
98 
99 typedef uint8_t SEAP_cflags_t;
100 
101 #define SEAP_CFLG_THREAD 0x01
102 #define SEAP_CFLG_WATCH 0x02
103 
104 /* Backends */
105 #include "seap-command-backendT.h"
106 
107 typedef struct {
108  SEAP_CTX_t *ctx;
109  int sd;
110  SEAP_cmd_t *cmd;
111 } SEAP_cmdjob_t;
112 
113 SEAP_cmdjob_t *SEAP_cmdjob_new (void);
114 void SEAP_cmdjob_free (SEAP_cmdjob_t *j);
115 
116 SEXP_t *SEAP_cmd2sexp (SEAP_cmd_t *cmd);
117 
118 
119 #endif /* _SEAP_COMMAND_H */
Definition: _seap-types.h:36
Definition: _seap-command.h:55
Definition: _seap-command.h:46
Definition: _seap-command.h:107
Definition: _seap-command.h:65
Definition: _seap-command.h:74
Definition: sexp-types.h:82