00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef __STUB_PROBE
00024 #pragma once
00025 #ifndef _SEAP_DESCRIPTOR_H
00026 #define _SEAP_DESCRIPTOR_H
00027
00028 #include <errno.h>
00029 #include <pthread.h>
00030 #include <stdint.h>
00031 #include "generic/bitmap.h"
00032 #include "generic/pqueue.h"
00033 #include "_sexp-types.h"
00034 #include "_sexp-parser.h"
00035 #include "_sexp-output.h"
00036 #include "_seap-command.h"
00037 #include "public/seap-scheme.h"
00038 #include "public/seap-message.h"
00039 #include "public/seap-command.h"
00040 #include "public/seap-error.h"
00041 #include "../../../common/util.h"
00042
00043 OSCAP_HIDDEN_START;
00044
00045
00046
00047
00048 typedef struct {
00049 SEAP_msgid_t next_id;
00050 SEXP_t *sexpbuf;
00051 SEXP_ostate_t *ostate;
00052 SEXP_pstate_t *pstate;
00053 SEAP_scheme_t scheme;
00054 void *scheme_data;
00055
00056
00057 SEXP_t *msg_queue;
00058 SEXP_t *err_queue;
00059 SEXP_t *cmd_queue;
00060
00061 pqueue_t *pck_queue;
00062
00063
00064
00065 pthread_mutex_t w_lock;
00066 pthread_mutex_t r_lock;
00067
00068 SEAP_cmdid_t next_cid;
00069 SEAP_cmdtbl_t *cmd_c_table;
00070 SEAP_cmdtbl_t *cmd_w_table;
00071 } SEAP_desc_t;
00072
00073 #define SEAP_DESC_FDIN 0x00000001
00074 #define SEAP_DESC_FDOUT 0x00000002
00075 #define SEAP_DESC_SELF -1
00076
00077 typedef struct {
00078 SEAP_desc_t *sd;
00079 uint16_t sdsize;
00080 bitmap_t bitmap;
00081 } SEAP_desctable_t;
00082
00083 #define SEAP_DESCTBL_INITIALIZER { NULL, 0, BITMAP_INITIALIZER }
00084
00085 #define SEAP_BUFFER_SIZE 2*4096
00086 #define SEAP_MAX_OPENDESC 128
00087 #define SDTABLE_REALLOC_ADD 4
00088
00089 int SEAP_desc_add (SEAP_desctable_t *sd_table, SEXP_pstate_t *pstate, SEAP_scheme_t scheme, void *scheme_data);
00090 int SEAP_desc_del (SEAP_desctable_t *sd_table, int sd);
00091 SEAP_desc_t *SEAP_desc_get (SEAP_desctable_t *sd_table, int sd);
00092
00093 static inline int SEAP_desc_trylock (pthread_mutex_t *m)
00094 {
00095 switch (pthread_mutex_trylock (m)) {
00096 case 0:
00097 return (1);
00098 case EBUSY:
00099 return (0);
00100 case EINVAL:
00101 errno = EINVAL;
00102 default:
00103 return (-1);
00104 }
00105 }
00106
00107 static inline int SEAP_desc_lock (pthread_mutex_t *m)
00108 {
00109 switch (pthread_mutex_lock (m)) {
00110 case 0:
00111 return (1);
00112 default:
00113 return (-1);
00114 }
00115 }
00116
00117 static inline int SEAP_desc_unlock (pthread_mutex_t *m)
00118 {
00119 switch (pthread_mutex_unlock (m)) {
00120 case 0:
00121 return (1);
00122 default:
00123 return (-1);
00124 }
00125 }
00126
00127 #define DESC_TRYRLOCK(d) SEAP_desc_trylock (&((d)->r_lock))
00128 #define DESC_RLOCK(d) SEAP_desc_lock (&((d)->r_lock))
00129 #define DESC_RUNLOCK(d) SEAP_desc_unlock (&((d)->r_lock))
00130
00131 #define DESC_TRYWLOCK(d) SEAP_desc_trylock (&((d)->w_lock))
00132 #define DESC_WLOCK(d) SEAP_desc_lock (&((d)->w_lock))
00133 #define DESC_WUNLOCK(d) SEAP_desc_unlock (&((d)->w_lock))
00134
00135 SEAP_msgid_t SEAP_desc_genmsgid (SEAP_desctable_t *sd_table, int sd);
00136 SEAP_cmdid_t SEAP_desc_gencmdid (SEAP_desctable_t *sd_table, int sd);
00137
00138 OSCAP_HIDDEN_END;
00139
00140 #endif
00141 #endif