Open SCAP Library
seap-descriptor.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  *
19  * Authors:
20  * "Daniel Kopecek" <dkopecek@redhat.com>
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  SEXP_ostate_t *ostate; /* Output state */
47  SEAP_scheme_t scheme; /* Protocol/Scheme used for this descriptor */
48  void *scheme_data; /* Protocol/Scheme related data */
49 
50  SEXP_t *msg_queue;
52  SEXP_t *cmd_queue;
53 
54  SEAP_packetq_t pck_queue;
55 
56  pthread_mutex_t w_lock;
57  pthread_mutex_t r_lock;
58 
59  SEAP_cmdid_t next_cid;
60  SEAP_cmdtbl_t *cmd_c_table; /* Local SEAP commands */
61  SEAP_cmdtbl_t *cmd_w_table; /* Waiting SEAP commands */
62  oval_subtype_t subtype;
63  struct probe_common_main_argument *arg;
64 } SEAP_desc_t;
65 
66 #define SEAP_DESC_FDIN 0x00000001
67 #define SEAP_DESC_FDOUT 0x00000002
68 #define SEAP_DESC_SELF -1
69 
70 #define SEAP_DESCTBL_INITIALIZER { NULL, NULL }
71 
72 #define SEAP_BUFFER_SIZE 2*4096
73 #define SEAP_MAX_OPENDESC 128
74 #define SDTABLE_REALLOC_ADD 4
75 
76 int SEAP_desc_add(SEAP_desctable_t *sd_table, SEAP_scheme_t scheme, void *scheme_data);
77 int SEAP_desc_del (SEAP_desctable_t *sd_table, int sd);
78 SEAP_desc_t *SEAP_desc_get (SEAP_desctable_t *sd_table, int sd);
79 
80 SEAP_desctable_t *SEAP_desctable_new (void);
81 void SEAP_desctable_free(SEAP_desctable_t *sd_table);
82 void SEAP_desc_free(SEAP_desc_t *dsc);
83 
84 static inline int SEAP_desc_trylock (pthread_mutex_t *m)
85 {
86  switch (pthread_mutex_trylock (m)) {
87  case 0:
88  return (1);
89  case EBUSY:
90  return (0);
91  case EINVAL:
92  errno = EINVAL;
93  /* FALLTHROUGH */
94  default:
95  return (-1);
96  }
97 }
98 
99 static inline int SEAP_desc_lock (pthread_mutex_t *m)
100 {
101  switch (pthread_mutex_lock (m)) {
102  case 0:
103  return (1);
104  default:
105  return (-1);
106  }
107 }
108 
109 static inline int SEAP_desc_unlock (pthread_mutex_t *m)
110 {
111  switch (pthread_mutex_unlock (m)) {
112  case 0:
113  return (1);
114  default:
115  return (-1);
116  }
117 }
118 
119 #define DESC_TRYRLOCK(d) SEAP_desc_trylock (&((d)->r_lock))
120 #define DESC_RLOCK(d) SEAP_desc_lock (&((d)->r_lock))
121 #define DESC_RUNLOCK(d) SEAP_desc_unlock (&((d)->r_lock))
122 
123 #define DESC_TRYWLOCK(d) SEAP_desc_trylock (&((d)->w_lock))
124 #define DESC_WLOCK(d) SEAP_desc_lock (&((d)->w_lock))
125 #define DESC_WUNLOCK(d) SEAP_desc_unlock (&((d)->w_lock))
126 
127 SEAP_msgid_t SEAP_desc_genmsgid (SEAP_desctable_t *sd_table, int sd);
128 SEAP_cmdid_t SEAP_desc_gencmdid (SEAP_desctable_t *sd_table, int sd);
129 
130 
131 #endif /* _SEAP_DESCRIPTOR_H */
oval_subtype_t
Unknown subtypes.
Definition: oval_types.h:120
Definition: _seap-packetq.h:16
Definition: probe_main.h:26
Definition: _sexp-output.h:36
Definition: seap-descriptor.h:44
Definition: _seap-types.h:41
Definition: _seap-types.h:36
Definition: rbt_common.h:129
Definition: sexp-types.h:82
Definition: err_queue.c:30