Debian Codegraph @

src/OVAL/probes/SEAP/seap-descriptor.h

raw symbols SCIP
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 *
19 * Authors:
20 * "Daniel Kopecek" <[email protected]>
21 */
22
23 #pragma once
24 #ifndef _SEAP_DESCRIPTOR_H
25 #define _SEAP_DESCRIPTOR_H
26
27 #include <errno.h>
28 #include <pthread.h>
29 #include <stdint.h>
30 #include "oval_types.h"
31 #include "generic/bitmap.h"
32 #include "generic/rbt/rbt.h"
33 #include "_sexp-types.h"
34 #include "_seap-packetq.h"
35 #include "_sexp-output.h"
36 #include "_seap-command.h"
37 #include "../../../common/util.h"
38
39 typedef uint8_t SEAP_scheme_t;
40
41 /*
42 * Descriptor table + related stuff
43 */
44 typedef struct {
45 SEAP_msgid_t next_id;
46 SEAP_scheme_t scheme; /* Protocol/Scheme used for this descriptor */
47 void *scheme_data; /* Protocol/Scheme related data */
48
49 SEXP_t *msg_queue;
50 rbt_t *err_queue;
51 SEXP_t *cmd_queue;
52
53 SEAP_packetq_t pck_queue;
54
55 pthread_mutex_t w_lock;
56 pthread_mutex_t r_lock;
57
58 SEAP_cmdid_t next_cid;
59 SEAP_cmdtbl_t *cmd_c_table; /* Local SEAP commands */
60 SEAP_cmdtbl_t *cmd_w_table; /* Waiting SEAP commands */
61 oval_subtype_t subtype;
62 struct probe_common_main_argument *arg;
63 } SEAP_desc_t;
64
65 #define SEAP_DESC_FDIN 0x00000001
66 #define SEAP_DESC_FDOUT 0x00000002
67 #define SEAP_DESC_SELF -1
68
69 #define SEAP_DESCTBL_INITIALIZER { NULL, NULL }
70
71 #define SEAP_BUFFER_SIZE 2*4096
72 #define SEAP_MAX_OPENDESC 128
73 #define SDTABLE_REALLOC_ADD 4
74
75 int SEAP_desc_add(SEAP_desctable_t *sd_table, SEAP_scheme_t scheme, void *scheme_data);
76 int SEAP_desc_del (SEAP_desctable_t *sd_table, int sd);
77 SEAP_desc_t *SEAP_desc_get (SEAP_desctable_t *sd_table, int sd);
78
79 SEAP_desctable_t *SEAP_desctable_new (void);
80 void SEAP_desctable_free(SEAP_desctable_t *sd_table);
81 void SEAP_desc_free(SEAP_desc_t *dsc);
82
83 static inline int SEAP_desc_trylock (pthread_mutex_t *m)
84 {
85 switch (pthread_mutex_trylock (m)) {
86 case 0:
87 return (1);
88 case EBUSY:
89 return (0);
90 case EINVAL:
91 errno = EINVAL;
92 /* FALLTHROUGH */
93 default:
94 return (-1);
95 }
96 }
97
98 static inline int SEAP_desc_lock (pthread_mutex_t *m)
99 {
100 switch (pthread_mutex_lock (m)) {
101 case 0:
102 return (1);
103 default:
104 return (-1);
105 }
106 }
107
108 static inline int SEAP_desc_unlock (pthread_mutex_t *m)
109 {
110 switch (pthread_mutex_unlock (m)) {
111 case 0:
112 return (1);
113 default:
114 return (-1);
115 }
116 }
117
118 #define DESC_TRYRLOCK(d) SEAP_desc_trylock (&((d)->r_lock))
119 #define DESC_RLOCK(d) SEAP_desc_lock (&((d)->r_lock))
120 #define DESC_RUNLOCK(d) SEAP_desc_unlock (&((d)->r_lock))
121
122 #define DESC_TRYWLOCK(d) SEAP_desc_trylock (&((d)->w_lock))
123 #define DESC_WLOCK(d) SEAP_desc_lock (&((d)->w_lock))
124 #define DESC_WUNLOCK(d) SEAP_desc_unlock (&((d)->w_lock))
125
126 SEAP_msgid_t SEAP_desc_genmsgid (SEAP_desctable_t *sd_table, int sd);
127 SEAP_cmdid_t SEAP_desc_gencmdid (SEAP_desctable_t *sd_table, int sd);
128
129
130 #endif /* _SEAP_DESCRIPTOR_H */